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-built Grafana system, or obtain the data of Managed Service for Prometheus for custom development. This topic describes how to use an HTTP API URL to import the monitoring data of a Prometheus instance to your self-built Grafana system, and obtain the data of Managed Service for Prometheus.

Obtain an HTTP API URL

  1. Log on to the ARMS console.
  2. In the left-side navigation pane, choose Prometheus Service > Prometheus Instances.
  3. On the Managed Service for Prometheus page, select the region where the Prometheus instance that you want to manage is created and click Settings in the Actions column.
  4. On the Settings tab, copy an HTTP API URL for access from the Internet or from an internal network.
    Note If the Prometheus instance is created to monitor a cloud service, copy the corresponding HTTP API URL based on the type of the cloud service.
    pg_pm_settings_tab_agent_settings
  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.
    Copy a token

Import the monitoring data of the Prometheus instance to your self-built Grafana system

  1. Configure a data source in the Grafana system.
    1. Log on to the local Grafana system as an administrator.
    2. In the left-side navigation pane, choose Configuration > Data Sources.
      Note This menu is visible only to the administrator.
    3. On the Data Sources tab, click Add data source.
    4. On the Add data source page, click Prometheus.
    5. On the Settings tab, enter a custom data source name in the Name field and paste the HTTP API URL obtained in Obtain an HTTP API URL in the URL field.
    6. Optional:In the Custom HTTP Headers section, click + Add header and set the Header parameter to Authorization and the Value parameter to the authentication token that you obtained in Obtain an HTTP API URL.
      tab_settings
    7. Click Save & Test.
  2. Verify the result.
    1. Log on to the local Grafana system.
    2. In the left-side navigation pane, select e > + New dashboard.
    3. On the New dashboard page, click Add an empty panel.
    4. On the Query tab of the New dashboard / Edit Panel page, select the data source added in Step 1 from the drop-down list. In the Metrics field of the A section, enter a metric name and press Enter.
      If a chart of the metric is displayed, the data source is added. Otherwise, check whether the URL or the authentication token that you entered is valid and whether the data source contains the monitoring data of Managed Service for Prometheus. pg_explore_with_metrics

Obtain the 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 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 Obtain an HTTP API URL.

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***"
                ]
            }
        ]
    }