信息
prometheus v2.1.0
redis_exporter v1.6.1
redis cluster 5.0 3 mater 3 slave
prometheus.yml
在prometheus.yml添加两个job,redis_exporter和redis_exporter_targets,redis_exporter_targets才是真正监控redis集群的。
## config for scraping the exporter itself
- job_name: 'redis_exporter'
static_configs:
- targets:
- prod-xxx-xxxx-redis01:9121
## config for the multiple Redis targets that the exporter will scrape
- job_name: 'redis_exporter_targets'
static_configs:
- targets:
- redis://172.16.0.122:7000
- redis://172.16.0.122:7001
- redis://172.16.0.120:7002
- redis://172.16.0.120:7003
- redis://172.16.0.129:7004
- redis://172.16.0.129:7005
metrics_path: /scrape
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: prod-xxxx-xxxx-redis01:9121
docker部署redis_exporter
REDIS_ADDR为你redis集群的其中一个节点即可,默认redis_exporter 使用9121端口!!
docker run -d -e REDIS_ADDR=172.16.0.120:7002 -e REDIS_PASSWORD=123456 --name redis_exporter --restart=always -p 9121:9121 oliver006/redis_exporter
然后重启prometheus。
grafana模板
id 763
image.png
没有数据的话到prometheus 9090端口的target看看我们新建的job target 是否 为 up 的状态。
image.png 实例配置:
cat prometheus-additional.yaml - job_name: 'redis_exporter' static_configs: - targets: - 10.96.48.195:9121 - job_name: 'redis_exporter_targets' static_configs: - targets: - redis://cloud-redis-0.test:6379 - redis://cloud-redis-1.test:6379 - redis://cloud-redis-2.test:6379 - redis://cloud-redis-3.test:6379 - redis://cloud-redis-4.test:6379 - redis://cloud-redis-5.test:6379 metrics_path: /metrics relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - target_label: __address__ replacement: 10.96.48.195:9121
cat redis-exporter-service.yaml apiVersion: v1 kind: Service metadata: labels: app: redis-exporter k8s.kuboard.cn/name: redis-exporter name: redis-exporter namespace: monitoring spec: externalTrafficPolicy: Cluster ports: - name: wzhxkx nodePort: 31107 port: 9121 protocol: TCP targetPort: 9121 selector: app: redis-exporter sessionAffinity: None type: NodePort status: loadBalancer: {}
cat redis-exporter-deploy.yaml apiVersion: apps/v1 kind: Deployment metadata: labels: app: redis-exporter k8s.kuboard.cn/name: redis-exporter name: redis-exporter namespace: monitoring spec: progressDeadlineSeconds: 600 replicas: 1 revisionHistoryLimit: 10 selector: matchLabels: app: redis-exporter strategy: rollingUpdate: maxSurge: 25% maxUnavailable: 25% type: RollingUpdate template: metadata: creationTimestamp: null labels: app: redis-exporter spec: containers: - args: - -redis.addr - redis://redis-cluster.test:6379 image: oliver006/redis_exporter:latest imagePullPolicy: Always name: redis-exporter ports: - containerPort: 9121 name: http protocol: TCP resources: {} terminationMessagePath: /dev/termination-log terminationMessagePolicy: File dnsPolicy: ClusterFirst restartPolicy: Always schedulerName: default-scheduler securityContext: {} terminationGracePeriodSeconds: 30
kubectl get svc -n test |grep redis cloud-redis NodePort 10.96.64.81 <none> 6379:31379/TCP 265d cloud-redis-0 NodePort 10.96.255.163 <none> 6379:31380/TCP 64d cloud-redis-1 NodePort 10.96.181.147 <none> 6379:31381/TCP 64d cloud-redis-2 NodePort 10.96.203.189 <none> 6379:31382/TCP 64d cloud-redis-3 NodePort 10.96.155.12 <none> 6379:31383/TCP 64d cloud-redis-4 NodePort 10.96.249.50 <none> 6379:31384/TCP 64d cloud-redis-5 NodePort 10.96.179.124 <none> 6379:31385/TCP 64d
prometheus 显示的targets
参考文档:
https://www.jianshu.com/p/2ead2f0dd325标签:__,exporter,name,6379,redis,cluster,prometheus,cloud From: https://www.cnblogs.com/weifeng1463/p/16617374.html