全部产品
Search
文档中心

应用实时监控服务ARMS:使用Prometheus监控腾讯云资源

更新时间:Apr 12, 2024

本文介绍如何使用阿里云Prometheus实现对腾讯云云资源的监控。

前提条件

背景信息

利用开源的腾讯云监控Exporter(qcloud exporter)可以将腾讯云监控支持的产品监控指标自动批量导出为Prometheus格式,使用Prometheus拉取qcloud exporter指标即可实现对腾讯云资源的监控。

腾讯云云监控(Cloud Monitor,简称CM)是一项可对腾讯云云资源实时监控和告警的服务,为用户提供统一监控云服务器、云数据库等所有云产品的平台。qcloud exporter是Prometheus Third-party exporters一种实现,当前支持的腾讯云资源列表如下:

产品

命名空间

支持的指标

MongoDB

QCE/CMONGO

指标详情

CDB

QCE/CDB

指标详情

Redis标准版

QCE/REDIS

暂无指标详情说明

Redis集群版

QCE/REDIS_CLUSTER

暂无指标详情说明

Redis内存版监控指标

QCE/REDIS_MEM

指标详情

CVM

QCE/CVM

指标详情

COS

QCE/COS

指标详情

CDN

QCE/CDN

指标详情

CLB(公网)

QCE/LB_PUBLIC

指标详情

CLB(7层)

QCE/LOADBALANCE

指标详情

NAT

QCE/NAT_GATEWAY

指标详情

物理专线

QCE/DC

指标详情

专用通道

QCE/DCX

指标详情

云硬盘

QCE/CBS

指标详情

SqlServer

QCE/SQLSERVER

指标详情

MariaDB

QCE/MARIADB

指标详情

Elasticsearch

QCE/CES

指标详情

CMQ队列服务

QCE/CMQ

指标详情

CMQ主题订阅

QCE/CMQTOPIC

指标详情

PostgreSQL

QCE/POSTGRES

指标详情

CKafka实例

QCE/CKAFKA

指标详情

Memcached

QCE/MEMCACHED

暂无指标详情说明

Lighthouse

QCE/LIGHTHOUSE

暂无指标详情说明

分布式数据库TDSQL MySQL实例

QCE/TDMYSQL

指标详情

弹性公网IP

QCE/LB

指标详情

操作流程

通过阿里云Prometheus配置监控腾讯云的操作流程如下图所示。

image

步骤一:部署qcloud exporter

  1. 构造镜像。

    git clone https://github.com/tencentyun/tencentcloud-exporter.git
    make build
  2. 定义产品实例配置。

    • 配置云API的credential认证信息

    • 配置产品products指标、实例导出信息

    例如,若您需要导出云服务器CVM所有指标和实例信息,您可以执行如下代码段。

    credential:
      access_key: "access_key"  #云API的SecretId
      secret_key: "secret_key"  #云API的SecretKey
      region: "ap-nanjing"      #实例所在区域信息
    
    rate_limit: 15              #云监控拉数据接口最大限制, 20次/秒, 1200次/分钟, https://cloud.tencent.com/document/product/248/31014
    
    products:
      - namespace: QCE/CVM      #指标详情: https://cloud.tencent.com/document/product/248/6843
        all_metrics: true       #导出支持的所有指标
        all_instances: true     #导出region下的所有实例
        #only_include_metrics: []
        #only_include_instances: [ins-xxxxxxxx]
        extra_labels: [InstanceId, InstanceName] #将实例的字段作为指标的labels导出
        #statistics_types: [last]
        #period_seconds: 60
        #metric_name_type: 2
    说明

    更多qcloud.yaml配置详情,请参见 tencentcloud-exporter

  3. 部署qcloud exporter。

    将以上配置文件构建到Docker镜像并将镜像上传到镜像仓库,如DockerHub、阿里云容器镜像服务ACR

    1. 登录容器服务管理控制台

    2. 在左侧导航栏中,单击集群

    3. 集群列表页面,单击目标集群右侧操作应用管理

    4. 创建容器组。

      1. 在左侧导航栏,选择工作负载 > 无状态

      2. 无状态页面,单击使用YAML创建资源

      3. 创建页面的模板代码框输入以下内容,然后单击创建

        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

        无状态页面会显示创建的容器组。rfv

    5. 创建服务。

      1. 在左侧导航栏,选择网络 > 服务

      2. 服务页面,单击使用YAML创建资源

      3. 创建页面的模板代码框输入以下内容,然后单击创建

        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

        服务页面会显示创建的服务。enj

步骤二:配置服务发现

配置可观测监控 Prometheus 版的服务发现以接收qcloud exporter数据的操作步骤如下:

重要

请确认阿里云容器服务K8s集群已接入可观测监控 Prometheus 版。具体操作,请参见Prometheus实例 for 容器服务

  1. 登录ARMS控制台
  2. 在左侧导航栏选择Prometheus监控 > 实例列表

  3. 在顶部菜单栏,选择K8s集群所在的地域,然后单击目标实例名称。

  4. 在左侧导航树单击服务发现,然后单击配置页签。

  5. 配置页面单击ServiceMonitor页签,然后单击添加ServiceMonitor,在弹出的添加ServiceMonitor对话框中输入以下内容,单击确定

    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

    ServiceMonitor页面会显示配置的服务发现。wert

步骤三:创建报警

创建Prometheus告警规则,具体操作,请参见Prometheus告警规则