目录
摘要:
监控策略:
export:
所要做的操作:
一. 引入predixy和redis的export
二. redis和predixy的pod都在vpc中, 无法直接访问. 所以要在agent中引入反向代理. 跳转访问
三. 在部署yaml中引入servicemonitor
四. 和监控测一起联调Prometheus中的数据是否正常
数据流动:
摘要:
说明redis监控的处理
监控策略:
使用Prometheus进行数据收集. 为简化收集接口, 直接使用export.
export:
redis: https://github.com/oliver006/redis_exporter/tree/renovate/redis-6.x
predixy: https://github.com/joyieldInc/predixy_exporter
所要做的操作:
一. 引入predixy和redis的export
需要注意都要跨平台编译
二. redis和predixy的pod都在vpc中, 无法直接访问. 所以要在agent中引入反向代理. 跳转访问
以nginx为反向代理, 毕竟最为稳定
三. 在部署yaml中引入servicemonitor
说明: Prometheus 监控服务 抓取配置说明 - 接入指南 - 文档中心 - 腾讯云
例子:
# Prometheus Operator CRD 版本
apiVersion: monitoring.coreos.com/v1
# 对应 K8S 的资源类型,这里面 Pod Monitor
kind: PodMonitor
# 对应 K8S 的 Metadata,这里只用关心 name,如果没有指定 jobLabel,对应抓取指标 label 中 job 的值为 <namespace>/<name>
metadata:
name: redis-exporter # 填写一个唯一名称
namespace: cm-prometheus # namespace固定,不需要修改
# 描述抓取目标 Pod 的选取及抓取任务的配置
spec:
# 填写对应 Pod 的 label,pod monitor 会取对应的值作为 job label 的值。
# 如果查看的是 Pod Yaml,取 pod.metadata.labels 中的值。
# 如果查看的是 Deployment/Daemonset/Statefulset,取 spec.template.metadata.labels。
[ jobLabel: string ]
# 把对应 Pod 上的 Label 添加到 Target 的 Label 中
[ podTargetLabels: []string ]
# 一次抓取数据点限制,0:不作限制,默认为 0
[ sampleLimit: uint64 ]
# 一次抓取 Target 限制,0:不作限制,默认为 0
[ targetLimit: uint64 ]
# 配置需要抓取暴露的 Prometheus HTTP 接口,可以配置多个 Endpoint
podMetricsEndpoints:
[ - <endpoint_config> ... ] # 详见下面 endpoint 说明
# 选择要监控 Pod 所在的 namespace,不填为选取所有 namespace
[ namespaceSelector: ]
# 是否选取所有 namespace
[ any: bool ]
# 需要选取 namespace 列表
[ matchNames: []string ]
# 填写要监控 Pod 的 Label 值,以定位目标 Pod [K8S metav1.LabelSelector](https://v1-17.docs.kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#labelselector-v1-meta)
selector:
[ matchExpressions: array ]
[ example: - {key: tier, operator: In, values: [cache]} ]
[ matchLabels: object ]
[ example: k8s-app: redis-exporter ]
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
name: redis-exporter # 填写一个唯一名称
namespace: cm-prometheus # namespace固定,不要修改
spec:
podMetricsEndpoints:
- interval: 30s
port: metric-port # 填写pod yaml中Prometheus Exporter对应的Port的Name
path: /metrics # 填写Prometheus Exporter对应的Path的值,不填默认/metrics
relabelings:
- action: replace
sourceLabels:
- instance
regex: (.*)
targetLabel: instance
replacement: 'crs-xxxxxx' # 调整成对应的 Redis 实例 ID
- action: replace
sourceLabels:
- instance
regex: (.*)
targetLabel: ip
replacement: '1.x.x.x' # 调整成对应的 Redis 实例 IP
namespaceSelector: # 选择要监控pod所在的namespace
matchNames:
- redis-test
selector: # 填写要监控pod的Label值,以定位目标pod
matchLabels:
k8s-app: redis-exporter
四. 和监控测一起联调Prometheus中的数据是否正常
数据流动:
节点图:
时序图: