All Products
Search
Document Center

Container Service for Kubernetes:Query Prometheus monitoring data by using PromQL

Last Updated:Aug 25, 2026

You can use Prometheus Query Language (PromQL) to query Prometheus monitoring data to verify the accuracy and timeliness of your alert rules.

Query Prometheus monitoring data in the console

Managed Service for Prometheus

For more information about deploying and using Managed Service for Prometheus, see Connect to and configure Managed Service for Prometheus.

  1. Log on to the ARMS console.

  2. In the left-side navigation pane, choose Prometheus Monitoring > Instance.

  3. In the upper-left corner of the Prometheus Monitoring page, select the region where your Container Service for Kubernetes (ACK) cluster is located. Find the target instance and click Shared Edition in the Grafana Workspace column.

  4. In the left-side navigation pane of the dashboard, click the 大盘 icon. In the upper-left corner, select the data source from the drop-down list to the right of Explore.

  5. In the text box to the right of Metric, enter a PromQL query and then click Run query.

Open source Prometheus

For more information about how to deploy open source Prometheus on an ACK cluster, see Open source Prometheus monitoring.

  1. Log on to the ACK console. In the left navigation pane, click Clusters.

  2. On the Clusters page, click the name of your cluster. In the left navigation pane, click Network > Services.

  3. On the Services page, select the monitoring namespace where ack-prometheus-operator is deployed. In the Actions column for ack-prometheus-operator-prometheus, click Update.

  4. In the dialog box, set Type to LoadBalancer. Select Create Resource, set Access Method to Public Access, and set Billing Method to Pay-as-you-go (Pay-by-CU). Click OK.

    See CLB Billing Overview.
  5. After the update, copy the external IP address. Open the Prometheus UI at <external_IP_address>:9090, for example, 47.XX.XX.12:9090.

  6. On the Prometheus console, click the Graph tab. In the text box, enter a PromQL query and click Execute.

Query monitoring data by API

Managed Service for Prometheus

  1. Log on to the ARMS console.

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

  3. At the top of the Instance page, select the region where your Prometheus instance is located. Find the target instance and click Settings in the Actions column.

  4. On the Settings page, in the HTTP API Address (Grafana Read Address) section, copy the public or internal HTTP API URL.

  5. For V1 Prometheus instances, if you need to improve the security of data reads in Grafana, click Generate token to obtain an authentication token for the Prometheus instance.

    Important
    • V1 instances: After you generate a token, you must configure it when you add the data source in Grafana. Otherwise, monitoring data cannot be read from the Prometheus instance.

    • V2 instances: By default, you must use your account's AccessKey ID and AccessKey secret to access data. The RAM user that owns the AccessKey ID must have the AliyunPrometheusMetricReadAccess or AliyunCloudMonitorFullAccess system permission.

  6. Use the HTTP API to query Prometheus monitoring data.

    The following code is an example request. For more information about how to use the HTTP API to obtain Prometheus monitoring data, see HTTP API.

    V1

    GET {HTTP API URL}/api/v1/query
    Accept: application/json
    Content-Type: application/json
    Authorization: {Token}
    {
      "query":"arms_prometheus_target_interval_length_seconds_sum",
      "time":"1635302655",
      "timeout":"1000"
    }

    V2

    GET {HTTP API URL}/api/v1/query
    Accept: application/json
    Content-Type: application/json
    Authorization: Basic <base64Encode(<AccessKey ID:AccessKey secret>)>
    {
      "query":"arms_prometheus_target_interval_length_seconds_sum",
      "time":"1635302655",
      "timeout":"1000"
    }

Open source Prometheus

  1. Obtain the HTTP API URL.

    If you access open source Prometheus from within a cluster, the default URL of the data request service for ack-prometheus-operator is http://ack-prometheus-operator-prometheus.monitoring:9090.

    If you use public access for open source Prometheus, attach a Classic Load Balancer (CLB) instance to the data request service for ack-prometheus-operator by following these steps:

    1. Log on to the ACK console. In the left navigation pane, click Clusters.

    2. On the Clusters page, click the name of your cluster. In the left navigation pane, click Network > Services.

    3. At the top of the Services page, set Namespace to monitoring. Find ack-prometheus-operator-prometheus and click Update in the Actions column.

    4. In the Update Service dialog box, configure the following parameters and click Update.

      Parameter

      Configuration

      Service Type

      Set Service Type to LoadBalancer and set the access method to Public Access.

      Port Mapping

      Enter a port name. Set Service Port to 9090, Container Port to 9090, and Protocol to TCP.

    5. On the Services page, click the ack-prometheus-operator-prometheus service. In the Basic Information section, obtain the External IP. This is the HTTP API URL.

  2. Use the HTTP API to query Prometheus monitoring data.

    • Obtain instant monitoring data.

      GET {HTTP API}/api/v1/query
      
      Headers:
      Accept: application/json
      Content-Type: application/json
      Param:
      {
        "query":"{{PromQL}}",
        "time":"1635302655",
        "timeout":"1000"
      
      }
      • time: specifies the point in time to query the data.

      • timeout: specifies the timeout in milliseconds. If a query exceeds this timeout, the current result is returned.

    • Query monitoring data over a time range.

      GET {HTTP API}/api/v1/query_range
      
      Headers:
      Accept: application/json
      Content-Type: application/json
      Param:
      {
        "query":"{{PromQL}}",
        "start": 1673946024,
        "end": 1673949624,
        "step": 30
      }
      • start: specifies the start time of the query.

      • end: specifies the end time of the query.

      • step: specifies the time step between data points in the returned monitoring data.

Related documents

To create alert rules by using custom PromQL queries, see Best practices for configuring alert rules by using Prometheus.