All Products
Search
Document Center

Application Real-Time Monitoring Service:Use an HTTP API URL to connect a Prometheus instance to a self-managed Grafana system

Last Updated:Jun 14, 2024

Alibaba Cloud Managed Service for Prometheus provides HTTP API URLs. You can use an HTTP API URL to import the monitoring data of a Prometheus instance to your self-managed Grafana system, or use the Prometheus API to obtain monitoring data for custom development.

Prerequisites

A Prometheus instance is created. For more information, see the following topics:

Step 1: Obtain the HTTP API URL

  1. Log on to the ARMS console.

  2. In the left-side navigation pane, choose Managed Service for Prometheus > Instances.

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

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

    Note

    If the Prometheus instance is created to monitor an Alibaba Cloud service, select an HTTP API URL based on the type of the cloud service.

    image

  5. Optional: Click Generate Token to obtain the authentication token for the Prometheus instance. The token is used to ensure data security when monitoring data is imported to Grafana.

    Important

    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.

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. 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

    8. Click Save & test.

  2. 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 the monitoring data of Managed Service for Prometheus

The sample request shows how to call the data of Managed Service for Prometheus. For information about how to use the HTTP API to obtain the data of Managed Service for Prometheus, see Prometheus HTTP API.

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 the {HTTP API} parameter with the actual HTTP API URL and the {Token} parameter with the actual authentication token. For more information, see 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***"
                ]
            }
        ]
    }