You can use PromQL to query Prometheus monitoring data to verify the validity and timeliness of alert rules. This topic describes how to use PromQL to query Prometheus monitoring data.
Table of contents
Use the console to query Prometheus monitoring data
Use the console to query the monitoring data of Prometheus Service
- Log on to the ARMS console.
- In the left-side navigation pane, choose .
- In the upper-left corner of the Prometheus Monitoring page, select the region in which your Container Service for Kubernetes (ACK) cluster is deployed and click the Prometheus instance that you want to manage.
- In the left-side navigation pane, click Dashboards. On the page that appears, click the name of the dashboard that you want to view.
- In the left-side navigation pane of the dashboard page, click the icon. In the upper part of the page, select a data source and enter a PromQL statement to query the monitoring data.
Use the console to query the monitoring data of open source Prometheus
- Run the following command to map Prometheus in the cluster to local port 9090:
kubectl port-forward svc/ack-prometheus-operator-prometheus 9090:9090 -n monitoring
- Enter localhost:9090 into the address bar of the web browser to query the monitoring data by using PromQL on the homepage of the console.
Use the API to query Prometheus monitoring data
Use the API to query the monitoring data of Prometheus Service
- Log on to the ARMS console.
- In the left-side navigation pane, choose .
- On the Prometheus Monitoring page, select the region where the Prometheus instance that you want to manage is deployed and click Settings in the Actions column.
- On the Settings page, copy the public or internal endpoint of the Prometheus instance in the HTTP API Address section. The endpoint is used to import monitoring data to Grafana.
- 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 a token is generated, you must specify the token when you add the Prometheus instance to your Grafana dashboard as a data source. Otherwise, monitoring data cannot be read from the Prometheus instance.
- Send HTTP API requests to query the monitoring data of Prometheus Service. The following code block provides an example. For more information, see 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" }
Use the API to query the monitoring data of open source Prometheus
- Obtain the HTTP API endpoint.
If you access open source Prometheus from within the cluster, the default endpoint of the Service used to expose the ack-prometheus-operator component is http://ack-prometheus-operator-prometheus.monitoring:9090.
If you access open source Prometheus over the Internet, you must associate a Server Load Balancer (SLB) instance with the Service used to expose the ack-prometheus-operator component. To do this, perform the following steps.
- Send HTTP API requests to query the monitoring data of Prometheus Service.
- Query real-time monitoring data. The following code block provides an example:
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 when the monitoring data is generated.
- timeout: specifies the timeout period of the query. Unit: milliseconds.
- Query the monitoring data that is generated within the specified 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: the start time.
- end: the end time.
- step: the interval between data points.
- Query real-time monitoring data. The following code block provides an example: