This topic describes how to use Alibaba Cloud Managed Service for Prometheus to monitor Tencent Cloud resources.
Prerequisites
A Container Service for Kubernetes (ACK) cluster is created. For more information, see Create an ACK dedicated cluster.
The ACK cluster is monitored in Managed Service for Prometheus. For more information, see Monitor an ACK cluster.
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 | |
Cloud Database | QCE/CDB | |
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 | |
Cloud Virtual Machine | QCE/CVM | |
Cloud Object Storage | QCE/COS | |
Content Delivery Network | QCE/CDN | |
Cloud Load Balancer (Internet) | QCE/LB_PUBLIC | |
Cloud Load Balancer (Layer 7) | QCE/LOADBALANCE | |
NAT Gateway | QCE/NAT_GATEWAY | |
Direct Connect (connection) | QCE/DC | |
Direct Connect (dedicated tunnel) | QCE/DCX | |
Cloud Block Storage | QCE/CBS | |
TencentDB for SQL Server | QCE/SQLSERVER | |
TencentDB for MariaDB | QCE/MARIADB | |
Elasticsearch Service | QCE/CES | |
Cloud Message Queue (queue service) | QCE/CMQ | |
Cloud Message Queue (topic subscription) | QCE/CMQTOPIC | |
TencentDB for PostgreSQL | QCE/POSTGRES | |
CKafka | QCE/CKAFKA | |
Memcached | QCE/MEMCACHED | None |
Lighthouse | QCE/LIGHTHOUSE | None |
TDSQL for MySQL | QCE/TDMYSQL | |
Elastic IP | QCE/LB |
Procedure
The following figure describes how to use Managed Service for Prometheus to monitor a Tencent Cloud resource:
Step 1: Deploy the QCloud exporter
Build an image.
git clone https://github.com/tencentyun/tencentcloud-exporter.git make build
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
NoteFor more information about how to configure the QCloud.yaml file, see tencentcloud-exporter.
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.
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 Applications in the Actions column.
Create a container group.
In the left-side navigation pane, choose
.On the Deployments page, click Create from YAML.
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
Create a service.
In the left-side navigation pane, choose
.On the Services page, click Create Resources in YAML.
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:
Make sure that the ACK cluster is monitored in Managed Service for Prometheus. For more information, see Use a Prometheus instance for Container Service .
Log on to the Managed Service for Prometheus console.
In the left-side navigation pane, click Instances.
In the top navigation bar, select the region where the ACK cluster resides, and click the name of the cluster.
In the left-side navigation pane, click Service Discovery. Then, click the Configure tab.
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.
Step 3: Create an alert rule
Create an alert rule. For more information, see Create an alert rule for a Prometheus instance.