Obtaining Prometheus Data Using PromQL Statements
Prometheus Query Language (PromQL) is a language that retrieves and consolidates time series data. Prometheus, an open-source monitoring system, is responsible for collecting and storing this data. Each time series has a unique identifier and a series of timestamp-value pairs. PromQL is a fundamental part of Prometheus, using simple expressions that include identifiers and tags to retrieve and consolidate time series data. This allows you to quickly identify and resolve issues as needed.
For details about how to use PromQL, see QUERYING PROMETHEUS.
Obtaining Huawei Cloud Prometheus Monitoring Data from the Console
- Install the Cloud Native Cluster Monitoring add-on in a cluster to collect Prometheus monitoring data.
- Log in to the CCE console and click the cluster name to access the cluster console. In the navigation pane, choose Add-ons.
- Locate the Cloud Native Cluster Monitoring add-on and click Install.
You are advised to focus on the following configurations, and adjust any other configurations as necessary. For details, see Cloud Native Cluster Monitoring.
- Report Monitoring Data to AOM: After this function is enabled, the add-on will report monitoring data to AOM.
- Target AOM Instance: Select an AOM instance for the add-on to report metrics.
- Click Install.
- Go to the AOM console to check monitoring data.
- Log in to the AOM 2.0 console. In the navigation pane, choose Metric Browsing.
- Select the Prometheus instance interconnected with AOM, select Prometheus statement.
For example, to obtain the number of requests received by CoreDNS and the response success rate, run the following PromQL statement:
sum(rate(coredns_dns_responses_total{instance=~"10.0.0.2:9153",rcode=~"NOERROR|NXDOMAIN"}[5m]))/sum(rate(coredns_dns_responses_total{instance=~"10.0.0.2:9153"}[5m]))
10.0.0.2 is the IP address of the CoreDNS container. The following figure shows the command output.
Obtaining Open-Source Prometheus Monitoring Data Through the Console
- After the Cloud Native Cluster Monitoring add-on is installed in a cluster, create a NodePort or LoadBalancer Service for Prometheus to access the external networks.
After external access is provided, you can access the Prometheus web page without authentication, which poses security risks. If you have high security requirements, you can do security hardening. You can use, for example, the Nginx reverse proxy and HTTP basic authentication to protect the console and restrict users who can access the Prometheus web page.
The following shows an example for creating a NodePort Service:apiVersion: v1 kind: Service metadata: name: prom-np labels: app.kubernetes.io/name: prometheus prometheus: server namespace: monitoring spec: selector: app.kubernetes.io/name: prometheus prometheus: server externalTrafficPolicy: Cluster ports: - name: cce-service-0 targetPort: 9090 nodePort: 0 port: 9090 protocol: TCP type: NodePort
- After an EIP is bound to a node, enter Node EIP:Node port in the address box of a browser to obtain the monitoring data through PromQL.
Obtaining Huawei Cloud Prometheus Monitoring Data Through APIs
- Log in to the AOM 2.0 console. In the navigation pane, choose Prometheus Monitoring > Instances.
- Click the name of the Prometheus instance interconnected with AOM and click Settings.
- Check the Grafana data source configurations and copy the public or intranet HTTP URL as required.
If no access code is created, create one first.
- Use an HTTP URL to obtain Prometheus monitoring data.
The following shows an example. (For more information about how to use HTTP APIs to obtain Prometheus monitoring data, see HTTP API.)
GET <HTTP URL>/api/v1/query Content-Type: application/json Authorization: <Token> { "query":" coredns_dns_responses_total", "time":" 1708655317.719", "timeout":"1000" }
In the preceding command, <HTTP URL> specifies the HTTP URL in the previous step, and <Token> specifies the password obtained in the previous step. Other URL query parameters are as follows:
- query: Prometheus expression query string
- time: timestamp for obtaining monitoring data
- timeout: timeout interval, in milliseconds
The following shows an example command:
curl -H 'Authorization: <Token>' -H 'Content-Type: application/json' -X GET '<HTTP URL>/api/v1/query?query=coredns_dns_responses_total&time=1708655317.719&timeout=1000'
The expected results are as follows:
Obtaining Open-Source Prometheus Monitoring Data Through APIs
- Obtain the HTTP API URL.
- If you access open-source Prometheus in a cluster, the HTTP API UR is the default Service address http://<cluster IP>:9090 of Prometheus server.
- If you use the public network to access open-source Prometheus, you need to associate a LoadBalancer Service to the Prometheus server. http://<ELB IP>:9090 is the HTTP API URL.
- Use HTTP APIs to obtain Prometheus monitoring data.
The following describes how to obtain open-source Prometheus monitoring data through the HTTP APIs in the cluster.
- Obtain instantaneous monitoring data.
GET <HTTP API>/api/v1/query Content-Type: application/json Param: { "query":" coredns_dns_responses_total", "time":" 1708655317.719", "timeout":"1000" }
The following shows an example command:
curl -X GET -H "Content-Type: application/json" '<HTTP API>/api/v1/query?query=coredns_dns_responses_total&time=1708655317&timeout=1000'
The expected results are as follows:
- Obtain monitoring data within a specified time range.
GET <HTTP API>/api/v1/query Content-Type: application/json Param: { "query":" coredns_dns_responses_total", "start":1708655317, "end":1708655318, "step":30 }
Other URL query parameters are as follows:
- start: time when you start to obtain monitoring data
- end: time when you stop obtaining the monitoring data
- step: step of the data interval when the monitoring data is returned
The following shows an example statement:
curl -X GET -H "Content-Type: application/json" -H "Accept: application/json" '<HTTP API>/api/v1/query?query=coredns_dns_responses_total&start=1708655317&end=1708655318&setp=30'
The expected results are as follows:
- Obtain instantaneous monitoring data.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot