Use PromQL (Prometheus Query Language) to query Prometheus monitoring data and verify that alert rules are accurate and timely.
Query Prometheus monitoring data in the console
Managed Service for Prometheus
For information about deploying and using Managed Service for Prometheus, see Configure Managed Service for Prometheus.
-
Log on to the Application Real-Time Monitoring Service (ARMS) console.
-
In the left-side navigation pane, choose .
-
In the upper-left corner of the Prometheus Monitoring page, select the region where the Container Service for Kubernetes (ACK) cluster is located. Find the target instance and, in its Grafana Workspace column, click Shared Edition.
-
In the left-side navigation pane of the dashboard, click the
icon. In the upper-left corner, select the relevant data source from the drop-down list to the right of Explore. -
In the text box to the right of Metric, enter a PromQL query statement, then click Run query.
Open Source Prometheus
For information about deploying 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, click the name of your cluster. In the left navigation pane, click .
-
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.
-
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.
-
After the update, copy the external IP address. Open the Prometheus UI at
<external_IP_address>:9090, for example,47.XX.XX.12:9090. -
In the Prometheus console, click the Graph tab, enter a PromQL query statement in the text box, then click Execute.
Query Prometheus monitoring data by using the API
Managed Service for Prometheus
Log on to the ARMS console.
-
In the left navigation pane, choose .
-
At the top of the Instance page, select the region where the Prometheus instance is located. In the Actions column beside the target cluster, click Settings.
-
On the Settings page, in the HTTP API Address (Grafana Read Address) section, copy the public or internal HTTP API URL as needed.
-
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.
-
-
Use the HTTP API to query monitoring data in Managed Service for Prometheus.
The following example shows a request that queries monitoring data in Managed Service for Prometheus. For more operations that 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
-
Obtain the HTTP API URL.
When you access open source Prometheus monitoring from within a cluster, the default data request Service URL for ack-prometheus-operator is
http://ack-prometheus-operator-prometheus.monitoring:9090.If you access open source Prometheus monitoring over the public network, bind a Server Load Balancer (SLB) to the data request Service of ack-prometheus-operator. Follow these steps:
-
Log on to the ACK console. In the left navigation pane, click Clusters.
-
On the Clusters page, click the name of your cluster. In the left navigation pane, click .
-
At the top of the Services page, switch the namespace by setting Namespace to monitoring. Then locate ack-prometheus-operator-prometheus and, in the Actions column to its right, click Update.
-
In the Update Service dialog box, configure the following parameters, then 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
-
On the Services page, click the ack-prometheus-operator-prometheus Service. In the Basic Information table, obtain the External IP. This is the HTTP API URL.
-
-
Use the HTTP API to query Prometheus monitoring data.
-
Obtain instant monitoring data. The request parameters are as follows.
GET {HTTP API}/api/v1/query Headers: Accept: application/json Content-Type: application/json Param: { "query":"{{PromQL}}", "time":"1635302655", "timeout":"1000" }-
time: Set the exact point in time to query monitoring data.
-
timeout: Set the timeout in milliseconds. The result is returned directly when this value is exceeded.
-
-
Query monitoring data for 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: Set the start time of the monitoring data query.
-
end: Set the end time of the monitoring data query.
-
step: Set the time step between data points in the returned monitoring data.
-
-
References
To learn how to create alert rules with custom PromQL, see Configuring alert rules using Prometheus.