All Products
Search
Document Center

Managed Service for Prometheus:Use an HTTP API URL to access Prometheus data in a self-managed Grafana system or a custom application

Last Updated:Dec 03, 2025

Managed Service for Prometheus provides HTTP API URLs. You can use these URLs to access Prometheus monitoring data in your self-managed Grafana system or retrieve monitoring data using the Prometheus API for custom development.

Prerequisites

A Prometheus instance has been connected. For more information, see the following topics:

Step 1: Obtain the HTTP API URL

  1. Log on to the Cloud Monitor console. In the left navigation pane, choose Managed Service for Prometheus > Instances. The Instances page appears.

  2. In the top navigation bar, select the region where your Prometheus instance is deployed, find the Prometheus instance, and then click Settings in the Actions column.

  3. On the Settings tab, copy a public or internal HTTP API URL.

    image

  4. Optional. For a Prometheus V1 instance, click Generate Token to obtain an authentication token. The token is used to ensure data security when monitoring data is imported to Grafana.

    Important
    • For a Prometheus V1 instance: After the authentication token is generated, you must specify the token when you add the Prometheus instance to your Grafana system as a data source. Otherwise, monitoring data cannot be read from the Prometheus instance.

    • For a Prometheus V2 instance: By default, data access requires both an AccessKey ID and AccessKey secret of your account, and the associated RAM user must have the AliyunPrometheusMetricReadAccess or AliyunCloudMonitorFullAccess system permission.

Step 2: Add the HTTP API URL to the self-managed Grafana system

  1. Configure a data source in the Grafana system.

    1. Log on to the Grafana system as an administrator.

    2. Click the image icon in the upper-left corner of the page.

    3. In the left-side navigation pane, choose Configuration > Data sources.

      Note

      This menu is visible only to the administrator.

    4. On the Data sources tab, click + Add data source.

    5. On the Add data source page, click Prometheus.

    6. On the Settings tab, enter a dashboard name in the Name field, enter the Prometheus server URL that you obtained in Step 1: obtain the URL of the Prometheus server in the Prometheus server URL field of the HTTP section.

    7. Set up security enhancements.

      Prometheus V1 (Optional)

      If you have generated a token, click + Add header in the Custom HTTP Headers section, set the Header parameter to Authorization, and then set the Value parameter to the token generated in Step 1: Obtain the HTTP API URL.

      image

      Prometheus V2

      Turn on Basic auth. Set the User parameter to your AccessKey ID and set the Password parameter to your AccessKey secret.

      image

  2. Click Save & test.

  3. Verify the result.

    1. Log on to the Grafana system.

    2. Click the image icon in the upper-left corner of the page, and then click Dashboards in the left-side navigation pane.

    3. On the Dashboards page, click New, and then click New dashboard from the drop-down menu.

    4. Click + Add visualization.

    5. On the Select data source page, select a custom data source.

    6. On the Edit Panel page, enter the metric name and value in the Metrics and Label filters fields in the A section of the Query tab, and click Run queries.

      If a chart of the metric is displayed, the Prometheus data source is added. If no chart is displayed, the Prometheus data source fails to be added. Check whether the API URL or token is valid, and whether the data source has monitoring data.

      image

Step 3: Obtain Prometheus monitoring data

The following code provides an example of a request to retrieve Prometheus monitoring data. For more information about how to use the HTTP API to retrieve Prometheus monitoring data, see Prometheus HTTP API.

Prometheus V1

GET {HTTP API}/api/v1/query

Accept: application/json
Content-Type: application/json
Authorization: {Token}

{
  "query":"arms_prometheus_target_interval_length_seconds_sum",
  "time":"1635302655",
  "timeout":"1000"

}
Note

Replace {HTTP API} in the preceding code with the actual HTTP API URL and replace {Token} with the actual authentication token. For more information, see Step 1: Obtain the HTTP API URL.

Prometheus V2

GET {HTTP API}/api/v1/query

Accept: application/json
Content-Type: application/json
Authorization: Basic <base64Encode(<accessKey:secretKey>)>

{
  "query":"arms_prometheus_target_interval_length_seconds_sum",
  "time":"1635302655",
  "timeout":"1000"

}
Note

Replace {HTTP API} in the preceding code with the HTTP API URL obtained in Step 1: Obtain the HTTP API URL.

Sample response:

View the sample response

{
    "status": "success",
    "data": {
        "resultType": "vector",
        "result": [
            {
                "metric": {
                    "__name__": "arms_prometheus_target_interval_length_seconds_sum",
                    "instance": "localhost:9335",
                    "interval": "15s",
                    "job": "_arms-prom/kubelet/1"
                },
                "value": [
                    1635302655,
                    "146655.24420603***"
                ]
            },
            {
                "metric": {
                    "__name__": "arms_prometheus_target_interval_length_seconds_sum",
                    "instance": "localhost:9335",
                    "interval": "30s",
                    "job": "_arms-prom/kubelet/1"
                },
                "value": [
                    1635302655,
                    "879810.747346***"
                ]
            },
            {
                "metric": {
                    "__name__": "arms_prometheus_target_interval_length_seconds_sum",
                    "instance": "localhost:9335",
                    "interval": "20s",
                    "job": "_arms-prom/kubelet/1"
                },
                "value": [
                    1635302655,
                    "73320.13578499***"
                ]
            }
        ]
    }