You can use Prometheus Query Language (PromQL) to query Prometheus monitoring data to verify the validity and timeliness of alert rules.
Use the console to query Prometheus monitoring data
Managed Service for Prometheus
For more information about how to configure and use Managed Service for Prometheus, see Managed Service for Prometheus.
Log on to the ARMS console.
In the left-side navigation pane, choose
.In the top navigation bar, select the region in which your Container Service for Kubernetes (ACK) cluster is deployed. Find the instance that you want to manage, and click Shared Edition in the Grafana Workspace column.
In the left-side navigation pane of the Dashboards page, click the icon. Then, select a data source from the dropdown list next to Explore.
Enter a PromQL statement in the textfield next to Metrics and click Run query.
Open-source Prometheus
For more information about how to configure open-source Prometheus in an ACK cluster, see Use open-source Prometheus to monitor an ACK cluster.
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
Managed Service for Prometheus
Log on to the ARMS console.
In the left-side navigation pane, choose .
On the Instances 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 URL (Grafana Read URL) 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.
ImportantAfter 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 about how to retrieve Prometheus monitoring data using the HTTP API, 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" }
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.
Log on to the ACK console. In the left-side navigation pane, click Clusters.
On the Clusters page, find the cluster that you want to manage and click its name. In the left-side pane, choose .
In the upper part 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, configure the following parameters and click OK.
Parameter
Configuration
Service Type
Set Service Type to SLB and select Public Access for Access Method.
Port Mapping
Enter a port name, set Service Port to 9090, Container Port to 9090, and Protocol to TCP.
On the Services page, click ack-prometheus-operator-prometheus. In the Basic Information section, you can obtain the External IP, which is the HTTP API endpoint.
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.
References
For more information about how to create alert rules by using custom PromQL, see Best practices for configuring alert rules in Prometheus.