Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ Cloud Container Engine/ Best Practices/ Monitoring/ Obtaining Prometheus Data Using PromQL Statements

Obtaining Prometheus Data Using PromQL Statements

Updated on 2025-01-08 GMT+08:00

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

  1. Install the Cloud Native Cluster Monitoring add-on in a cluster to collect Prometheus monitoring data.

    1. Log in to the CCE console and click the cluster name to access the cluster console. In the navigation pane, choose Add-ons.
    2. 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.

    3. Click Install.

  2. Go to the AOM console to check monitoring data.

    1. Log in to the AOM 2.0 console. In the navigation pane, choose Metric Browsing.
    2. 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

  1. 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.

    NOTICE:

    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

  2. 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

  1. Log in to the AOM 2.0 console. In the navigation pane, choose Prometheus Monitoring > Instances.
  2. Click the name of the Prometheus instance interconnected with AOM and click Settings.
  3. Check the Grafana data source configurations and copy the public or intranet HTTP URL as required.

    NOTE:

    If no access code is created, create one first.

  4. 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

  1. 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.

  2. 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:

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback