Management API

Prometheus provides a set of management APIs that allow you to interact with and manage various aspects of the Prometheus server and its components. These APIs are useful for tasks such as querying metrics, retrieving configuration information, and managing runtime behavior. Here are some key management APIs provided by Prometheus:

1. Query API (/api/v1/query):

  • This API allows you to execute instant queries to retrieve metric data.
  • You can specify the metric name, labels, and time range to retrieve specific data points.
  • It returns a JSON response containing the query results.

2. Range Query API (/api/v1/query_range):

  • Similar to the Query API, but used for range queries over a time interval.
  • Useful for retrieving time series data for graphing or analysis.
  • Returns a JSON response with time series data points within the specified range.

3. Label Values API (/api/v1/label/your_label_name/values):

  • Allows you to retrieve the distinct values for a given label name.
  • Useful for dynamic label-based selection when querying metrics.

4. Targets API (/api/v1/targets):

  • Provides information about the targets that Prometheus is configured to scrape.
  • Includes details such as target's address, labels, last scrape timestamp, etc.

5. Alertmanager API (/api/v1/alerts):

  • Retrieves a list of active alerts along with their labels and annotations.
  • Useful for monitoring the current state of your alerting rules.

6. Configuration API (/api/v1/status/config):

  • Allows you to retrieve the effective runtime configuration of Prometheus.
  • Useful for validating or inspecting your Prometheus configuration.

7. Runtime Configuration Reload (/-/reload):

  • This API endpoint triggers a reload of the Prometheus configuration.
  • Changes made to the configuration file take effect after invoking this endpoint.

8. Metrics API (/metrics):

  • Prometheus itself exposes various internal metrics about its performance and behavior through this API.
  • These metrics can be scraped by another Prometheus instance or monitoring system to monitor the health of your Prometheus server.

It's important to note that these APIs are typically accessed using HTTP GET requests to the specified endpoints. Responses are usually in JSON format, making them easily consumable by scripts and applications.

Examples

Here are examples of HTTP requests for each of the Prometheus management APIs mentioned earlier. Keep in mind that you'll need to replace placeholders (such as label_name, target_id, etc.) with actual values relevant to your setup.

1. Query API (/api/v1/query):

Retrieve instant metric value for a specific metric and label combination.

GET /api/v1/query?query=your_metric_name{your_label_name="your_label_value"}

2. Range Query API (/api/v1/query_range):

Retrieve time series data for a specific metric and label combination within a time range.

GET /api/v1/query_range?query=your_metric_name{your_label_name="your_label_value"}&start=your_start_timestamp&end=your_end_timestamp&step=your_sampling_interval

3. Label Values API (/api/v1/label/your_label_name/values):

Retrieve distinct values for a specific label.

GET /api/v1/label/your_label_name/values

4. Targets API (/api/v1/targets):

Retrieve information about configured scrape targets.

GET /api/v1/targets

5. Alertmanager API (/api/v1/alerts):

Retrieve a list of active alerts.

GET /api/v1/alerts

6. Configuration API (/api/v1/status/config):

Retrieve the effective runtime configuration of Prometheus.

GET /api/v1/status/config

7. Runtime Configuration Reload (/-/reload):

Trigger a reload of the Prometheus configuration.

POST /-/reload

8. Metrics API (/metrics):

Retrieve internal metrics exposed by Prometheus itself.

GET /metrics

Please note that for many of these requests, you will need to replace placeholders like your_metric_name, your_label_name, your_label_value, your_start_timestamp, your_end_timestamp, your_sampling_interval, and so on with actual values.

Also, remember to access these APIs on the appropriate base URL where your Prometheus server is running. The examples shown here assume a generic base URL, so you will need to adjust them according to your Prometheus server's configuration and deployment.