All Products
Search
Document Center

Managed Service for Prometheus:Use Managed Service for Prometheus to monitor Tencent Cloud resources

Last Updated:Sep 09, 2024

This topic describes how to use Alibaba Cloud Managed Service for Prometheus to monitor Tencent Cloud resources.

Prerequisites

Background information

You can use the QCloud exporter to export metrics from Tencent Cloud Cloud Monitor (CM) to Managed Service for Prometheus. This allows you to monitor Tencent Cloud resources in Managed Service for Prometheus.

CM is a real-time monitoring and alerting service developed by Tencent Cloud. CM provides a platform for centralized monitoring of all Tencent Cloud offerings, such as Cloud Virtual Machine (CVM) and database services. The QCloud exporter is a third-party Prometheus exporter. The following table lists the Tencent Cloud resources that are supported by the QCloud exporter:

Service

Namespace

Metric

TencentDB for MongoDB

QCE/CMONGO

Metric details

Cloud Database

QCE/CDB

Metric details

TencentDB for Redis (standard architecture)

QCE/REDIS

None

TencentDB for Redis (cluster architecture)

QCE/REDIS_CLUSTER

None

TencentDB for Redis (Memory Edition)

QCE/REDIS_MEM

Metric details

Cloud Virtual Machine

QCE/CVM

Metric details

Cloud Object Storage

QCE/COS

Metric details

Content Delivery Network

QCE/CDN

Metric details

Cloud Load Balancer (Internet)

QCE/LB_PUBLIC

Metric details

Cloud Load Balancer (Layer 7)

QCE/LOADBALANCE

Metric details

NAT Gateway

QCE/NAT_GATEWAY

Metric details

Direct Connect (connection)

QCE/DC

Metric details

Direct Connect (dedicated tunnel)

QCE/DCX

Metric details

Cloud Block Storage

QCE/CBS

Metric details

TencentDB for SQL Server

QCE/SQLSERVER

Metric details

TencentDB for MariaDB

QCE/MARIADB

Metric details

Elasticsearch Service

QCE/CES

Metric details

Cloud Message Queue (queue service)

QCE/CMQ

Metric details

Cloud Message Queue (topic subscription)

QCE/CMQTOPIC

Metric details

TencentDB for PostgreSQL

QCE/POSTGRES

Metric details

CKafka

QCE/CKAFKA

Metric details

Memcached

QCE/MEMCACHED

None

Lighthouse

QCE/LIGHTHOUSE

None

TDSQL for MySQL

QCE/TDMYSQL

Metric details

Elastic IP

QCE/LB

Metric details

Procedure

The following figure describes how to use Managed Service for Prometheus to monitor a Tencent Cloud resource:

image

Step 1: Deploy the QCloud exporter

  1. Build an image.

    git clone https://github.com/tencentyun/tencentcloud-exporter.git
    make build
  2. Configure the resource and the instances.

    • Configure the credentials of TencentCloud API.

    • Configure the resource and the instances whose metrics you want to export.

    If you want to export all metrics of all CVM instances, you can use the following code:

    credential:
      access_key: "access_key"  #The SecretId of TencentCloud API.
      secret_key: "secret_key"  #The SecretKey of TencentCloud API.
      region: "ap-nanjing" #The region where the instances reside.
    
    rate_limit: 15              #The maximum number of API calls that CM can make per second to pull data. Example: 20. For more information, see https://cloud.tencent.com/document/product/248/31014.
    
    products:
      - namespace: QCE/CVM      #For more information about the metrics, see https://cloud.tencent.com/document/product/248/6843.
        all_metrics: true       #Specifies that all supported metrics are exported.
        all_instances: true     #Specifies that the metrics of all instances in the specified region are exported.
        #only_include_metrics: []
        #only_include_instances: [ins-xxxxxxxx]
        extra_labels: [InstanceId, InstanceName] #The metric labels to which the fields of instances are exported.
        #statistics_types: [last]
        #period_seconds: 60
        #metric_name_type: 2
    Note

    For more information about how to configure the QCloud.yaml file, see tencentcloud-exporter.

  3. Deploy the QCloud exporter.

    Create a Docker image by using the preceding YAML file and upload the image to an image repository, such as DockerHub or Alibaba Cloud Container Registry.

    1. Log on to the ACK console. In the left-side navigation pane, click Clusters.

    2. On the Clusters page, find the cluster that you want to manage and click Applications in the Actions column.

    3. Create a container group.

      1. In the left-side navigation pane, choose Workloads > Deployments.

      2. On the Deployments page, click Create from YAML.

      3. On the Create page, enter the following code in the Template code editor and click Create:

        apiVersion: apps/v1
        kind: Deployment
        metadata:
          generation: 5
          labels:
            app: qcloud-exporter-demo
          name: qcloud-exporter-demo
          namespace: default
        spec:
          replicas: 1
          selector:
            matchLabels:
              app: qcloud-exporter-demo
          template:
            metadata:
              labels:
                app: qcloud-exporter-demo
            spec:
              containers:
                - args:
                    - '--config.file=/usr/local/etc/qcloud-cvm-product.yml'
                  image: 'registry.cn-hangzhou.aliyuncs.com/fuling/qcloud-exporter:v0.1'
                  imagePullPolicy: Always
                  name: qcloud-exporter
                  ports:
                    - containerPort: 9123
                      name: web-normal
                      protocol: TCP
    4. Create a service.

      1. In the left-side navigation pane, choose Network > Services.

      2. On the Services page, click Create Resources in YAML.

      3. On the Create page, enter the following code in the Template code editor and click Create:

        apiVersion: v1
        kind: Service
        metadata:
          labels:
            app: qcloud-exporter-demo
          name: qcloud-exporter-demo-svc
          namespace: default
        spec:
          ports:
            - name: qcloud-exporter-metrics
              port: 9123
              protocol: TCP
              targetPort: 9123
          selector:
            app: qcloud-exporter-demo

Step 2: Add a service discovery configuration

To add a service discovery configuration in Managed Service for Prometheus to collect data from the QCloud exporter, perform the following steps:

Important

Make sure that the ACK cluster is monitored in Managed Service for Prometheus. For more information, see Use a Prometheus instance for Container Service .

  1. Log on to the Managed Service for Prometheus console.

  2. In the left-side navigation pane, click Instances.

  3. In the top navigation bar, select the region where the ACK cluster resides, and click the name of the cluster.

  4. In the left-side navigation pane, click Service Discovery. Then, click the Configure tab.

  5. On the Configure tab, click the ServiceMonitor tab and click Add ServiceMonitor. In the Add ServiceMonitor dialog box, enter the following code and click OK.

    apiVersion: monitoring.coreos.com/v1
    kind: ServiceMonitor
    metadata:
      name: qcloud-exporter-sm
      namespace: default
    spec:
      endpoints:
      - interval: 60s
        path: /metrics
        port: qcloud-exporter-metrics
        scrapeTimeout: 60s
      namespaceSelector:
        any: true
      selector:
        matchLabels:
          app: qcloud-exporter-demo

    The service discovery configuration is displayed on the ServiceMonitor tab.

    image

Step 3: Create an alert rule

Create an alert rule. For more information, see Create an alert rule for a Prometheus instance.