·服务器监控指标,例如 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}
注意:说明:
五、Prometheus
在 Prometheus 配置文件 中添加如下配置:
# 上报地址,请替换其中的${region}及${topicId},本示例采用外网地址,如果网络条件允许建议使用内网地址# 内网地址 url: https://${region}.cls.tencentyun.com/prometheus/${topicId}/api/v1/writeurl: 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
注意:说明:
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
注意:说明:
注意:queueConfig: capacity: 204800 minShards: 100 maxShards: 2048 maxSamplesPerSend: 4096 batchSendDeadline: 30s minBackoff: 100ms maxBackoff: 5s
4. 应用配置文件,例如如下命令:
kubectl apply -f prometheus-prometheus.yaml -n monitoring
注意:说明: