tencent cloud

日志服务

动态与公告
产品动态
公告
新手指引
产品简介
产品概述
产品优势
地域和访问域名
规格与限制
基本概念
购买指南
计费概述
产品定价
按量计费(后付费)
欠费说明
清理日志服务资源
成本优化
常见问题
快速入门
一分钟入门指南
入门指南
使用 Demo 日志快速体验 CLS
操作指南
资源管理
权限管理
日志采集
指标采集
日志存储
指标存储
检索分析(日志主题)
检索分析(指标主题)
仪表盘
数据处理
投递与消费
监控告警
云产品中心
DataSight 独立控制台
历史文档
实践教程
日志采集
检索分析
仪表盘
监控告警
投递和消费
成本优化
开发者指南
通过 iframe 内嵌 CLS(旧方案)
通过 Grafana 使用 CLS
API 文档
History
Introduction
API Category
Making API Requests
Topic Management APIs
Log Set Management APIs
Index APIs
Topic Partition APIs
Machine Group APIs
Collection Configuration APIs
Log APIs
Metric APIs
Alarm Policy APIs
Data Processing APIs
Kafka Protocol Consumption APIs
CKafka Shipping Task APIs
Kafka Data Subscription APIs
COS Shipping Task APIs
SCF Delivery Task APIs
Scheduled SQL Analysis APIs
COS Data Import Task APIs
Data Types
Error Codes
常见问题
健康监测问题解释
采集相关
检索分析相关
其他问题
服务等级协议
CLS 政策
隐私协议
数据处理和安全协议
联系我们
词汇表

指标上报

PDF
聚焦模式
字号
最后更新时间: 2026-02-04 18:06:27
指标主题支持 Prometheus Remote Write 协议,可使用兼容该协议的各类采集器采集指标并上报至指标主题,例如 vmagent 及 telegraf。通过这些采集器,您可以将各种类型的监控指标上报至指标主题,例如:
服务器监控指标,例如 CPU、内存、磁盘使用率等。
容器集群监控指标,例如 Pods 内存使用量、apiserver 请求延迟等。
中间件监控指标,例如 MySQL、Kafka、Nginx 等中间件的性能指标。
应用系统监控指标,例如接口吞吐率、响应时间、错误请求数等。
指标主题也可以作为本地 Prometheus 的远程存储,以 Remote Write 的方式将本地 Prometheus 中的指标上报至指标主题。

上报地址

网络类型
地址
外网
https://${region}.cls.tencentcs.com/prometheus/${topicId}/api/v1/write
内网
https://${region}.cls.tencentyun.com/prometheus/${topicId}/api/v1/write
其中:
${region}需替换为指标主题所在的地域,例如 ap-beijing,更多地域简称参见 可用地域,目前仅支持北京、上海、广州及南京地域。
${topicId}需替换为指标主题 ID,例如 0e69453c-0727-4c9c-xxxx-ea51b10d2aba,可在 指标主题列表 中查询。

鉴权方式

指标上报采用 Basic Auth 进行鉴权,将 API 密钥 中的 SecretId 及 SecretKey 分别作为 username 及 password。
username:${SecretId}
password:${SecretKey}
建议您为采集器单独创建一个子账号,使用该账号的 SecretId 及 SecretKey。该账号仅授予如下权限即可,以保障账号安全,配置方式详见 子账号授权
{
"version": "2.0",
"statement": [
{
"effect": "allow",
"action": [
"cls:MetricsRemoteWrite"
],
"resource": [
"*"
]
}
]
}

配置示例

Telegraf

在 Telegraf 配置文件 中添加如下的 output 配置:
[[outputs.http]]
## 上报地址,请替换其中的${region}及${topicId},本示例采用外网地址,如果网络条件允许建议使用内网地址
## 内网地址 url = "https://${region}.cls.tencentyun.com/prometheus/${topicId}/api/v1/write"
url = "https://${region}.cls.tencentcs.com/prometheus/${topicId}/api/v1/write"

## 鉴权信息,请替换其中的${SecretId}及${SecretKey}
username = "${SecretId}"
password = "${SecretKey}"

## Telegraf output 数据格式配置,请勿修改
data_format = "prometheusremotewrite"
[outputs.http.headers]
Content-Type = "application/x-protobuf"
Content-Encoding = "snappy"
X-Prometheus-Remote-Write-Version = "0.1.0"

Vmagent

启动 Vmagent 时使用如下参数配置 remoteWrite:
./vmagent-prod \\
-remoteWrite.url=https://${region}.cls.tencentcs.com/prometheus/${topicId}/api/v1/write \\
-remoteWrite.basicAuth.username=${SecretId} \\
-remoteWrite.basicAuth.password=${SecretKey}
说明:
其中 remoteWrite.url 为外网地址,如果网络条件允许建议使用内网地址。
内网地址为https://${region}.cls.tencentyun.com/prometheus/${topicId}/api/v1/write

Prometheus

在 Prometheus 配置文件 中添加如下配置:
# 上报地址,请替换其中的${region}及${topicId},本示例采用外网地址,如果网络条件允许建议使用内网地址
# 内网地址 url: https://${region}.cls.tencentyun.com/prometheus/${topicId}/api/v1/write
url: https://${region}.cls.tencentcs.com/prometheus/${topicId}/api/v1/write

# 鉴权信息,请替换其中的${SecretId}及${SecretKey}
basic_auth:
username: ${SecretId}
password: ${SecretKey}

# 数据写入策略,包括缓存及重试等,数据量较大时可参考如下配置
queue_config:
capacity: 20480
min_shards: 100
max_samples_per_send: 2048
batch_send_deadline: 20s
min_backoff: 100ms
max_backoff: 5s
更多配置说明,详见 Prometheus 官方文档

Prometheus Operator

使用 Prometheus Operator 在 Kubernetes 中部署的 Prometheus 可通过如下方式上报指标:
1. 使用 kubectl 创建鉴权所需的 Secret,例如如下命令:
kubectl create secret generic kubepromsecret \\
--from-literal=username=${SecretId} \\
--from-literal=password=${SecretKey} \\
-n monitoring
说明:
请替换其中的${SecretId}${SecretKey}
如果 Prometheus 部署在其它 namespace 中,请修改其中的-n monitoring为正确的 namespace。
也可以使用 manifest file 创建 Secret,详见 Kubernetes 官方文档
2. 打开 Prometheus manifest 配置文件,配置文件一般位于 Prometheus Operator 使用的 GitHub repo 文件夹中,路径一般为kube-prometheus/manifests/prometheus-prometheus.yaml
3. 修改 Prometheus manifest 配置文件,在末尾添加如下配置:
remoteWrite:
- url: "https://${region}.cls.tencentcs.com/prometheus/${topicId}/api/v1/write"
basicAuth:
username:
name: kubepromsecret
key: username
password:
name: kubepromsecret
key: password
说明:
请替换其中的${region}${topicId},本示例采用外网地址,如果网络条件允许建议使用内网地址。
内网地址为url: "https://${region}.cls.tencentyun.com/prometheus/${topicId}/api/v1/write"
数据量较大时可添加如下数据写入策略,包括缓存及重试等,详见 Prometheus-Operator 官方文档
queueConfig:
capacity: 204800
minShards: 100
maxShards: 2048
maxSamplesPerSend: 4096
batchSendDeadline: 30s
minBackoff: 100ms
maxBackoff: 5s
4. 应用配置文件,例如如下命令:
kubectl apply -f prometheus-prometheus.yaml -n monitoring
说明:
请替换prometheus-prometheus.yaml为正确的配置文件路径
如果 Prometheus 部署在其它 namespace 中,请修改其中的-n monitoring为正确的 namespace。


帮助和支持

本页内容是否解决了您的问题?

填写满意度调查问卷,共创更好文档体验。

文档反馈