You can use Prometheus Query Language (PromQL) to query Prometheus monitoring data. This helps you verify the accuracy and timeliness of your alert rules.
Query Prometheus monitoring data in the console
Managed Service for Prometheus
For more information about how to deploy and use Managed Service for Prometheus, see Use Managed Service for Prometheus.
Log on to the ARMS console.
In the navigation pane on the left, choose .
In the upper-left corner of the Managed Service for Prometheus page, select the region where your Container Service for Kubernetes (ACK) cluster is located. Click Shared Edition in the Grafana Workspace column of the target instance.
In the navigation pane on the left of the dashboard, click the
icon. Then, from the drop-down list to the right of Explore in the upper-left corner, select the appropriate data source.In the text box next to Metric, enter a PromQL query statement and click Run query.
Open source Prometheus
For more information about how to deploy open source Prometheus monitoring on an ACK cluster, see Open source Prometheus monitoring.
Log on to the ACK console. In the left navigation pane, click Clusters.
On the Clusters page, find the cluster you want and click its name. In the left-side pane, choose .
On the Services page, select the namespace in which the ack-prometheus-operator is deployed (monitoring by default). Find ack-prometheus-operator-prometheus and click Update in the Actions column.
In the Update Service dialog box, set Service Type to SLB. Select Create Resource and set Access Method to Public Access. Select Pay-as-you-go for the Billing Method parameter, configure other parameters as needed, and click OK.
See Classic Load Balancer (CLB) billing for details.
After the update is complete, copy its external IP address, and access Prometheus by entering the
IP address: port numberin the address bar of a browser. Example:47.XX.XX.12:9090.In the Prometheus console, click the Graph tab. In the text box, enter a PromQL query statement and click Execute.
Query Prometheus monitoring data using the API
Managed Service for Prometheus
Log on to the ARMS console.
In the left navigation pane, choose .
At the top of the Instances page, select the region where the Prometheus instance is located. In the Actions column for the target cluster, click Settings.
On the Settings page, in the HTTP API URL (Grafana Read URL) section, copy the public or internal HTTP API URL as needed.
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.
ImportantFor 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.
Call the HTTP API to query monitoring data from Managed Service for Prometheus.
The following code provides a request example for calling Managed Service for Prometheus to query monitoring data. For more information about how to use the HTTP API to retrieve Prometheus monitoring data, see HTTP API.
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" }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" }
Open source Prometheus
Obtain the HTTP API URL.
If you access open source Prometheus from within the cluster, the default service URL for data requests to ack-prometheus-operator is
http://ack-prometheus-operator-prometheus.monitoring:9090.If you access open source Prometheus over the Internet, you must attach an SLB instance to the ack-prometheus-operator service. To do this, perform the following steps.
Log on to the ACK console. In the left-side navigation pane, click Clusters.
On the Clusters page, find the cluster you want and click its name. In the left-side pane, choose .
At the top of the Services page, set Namespace to monitoring. Then, find ack-prometheus-operator-prometheus and click Update in the Actions column.
In the Update Service dialog box, set the following parameters and click Update.
Configuration item
Configuration
Service Type
Set Service Type to Server Load Balancer (LoadBalancer) and set Access Method to Public Access.
Port Mapping
Enter a port name. Set Service Port to 9090, Container Port to 9090, and Protocol to TCP.
On the Services page, click the ack-prometheus-operator-prometheus service. In the Basic Information section, obtain the External IP. The external IP address is the HTTP API URL.
Call the HTTP API to query Prometheus monitoring data.
To query instant monitoring data, use the following request parameters:
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 for the data query.
timeout: Specifies the timeout period. If the query exceeds this period, a result is returned. (Unit: milliseconds)
To query monitoring data over a time range, use the following request parameters:
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: The interval between data points in the returned monitoring data.
References
For information about how to create alert rules using custom PromQL, see Best practices for configuring alert rules using Prometheus.