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 basics.
Obtaining Huawei Cloud Prometheus Monitoring Data Through 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. Prioritize the configurations listed below and adjust any other configurations as needed. 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 metric reporting.

- Click Install.
- Go to the AOM console and check monitoring data.
- Log in to the AOM 2.0 console. In the navigation pane, choose Metric Browsing.
- Select the Prometheus instance connected to AOM and select Prometheus statement. For example, to obtain the number of requests received by CoreDNS and the response success rate, use 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 figure below shows the returned result.

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 bar 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 connected to AOM and click the Settings tab.
- 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.
An example is shown below. For details 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 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:
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 shown in the figure below.

Obtaining Open-Source Prometheus Monitoring Data Through APIs
- Obtain the HTTP API URL.
- If you access the open-source Prometheus from a cluster, the HTTP API URL is the default Service address http://<cluster IP>:9090 of the Prometheus server.
- If you access the open-source Prometheus from the Internet, you need to associate a LoadBalancer Service to the Prometheus server. http://<load-balancer-IP-address>:9090 is the HTTP API URL.
- Use HTTP APIs to obtain Prometheus monitoring data.
The following describes how to obtain the open-source Prometheus monitoring data through the HTTP APIs in a 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 shown in the figure below.

- 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 returns
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 shown in the figure below.

- 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
