当前位置:   article > 正文

【prometheus-operator】k8s监控redis

【prometheus-operator】k8s监控redis

1、准备exporter

https://github.com/oliver006/redis_exporter

oliver006-redis_exporter-amd64.tar

# 安装镜像

docker load -i oliver006-redis_exporter-amd64.tar

# 上传镜像
docker tag  oliver006/redis_exporter ip/monitor/redis_exporter:latest
docker push ip/monitor/redis_exporter:latest

2、部署exporter

  1. kind: Deployment
  2. apiVersion: apps/v1
  3. metadata:
  4. name: redis-exporter
  5. namespace: devops
  6. labels:
  7. app: redis-exporter
  8. annotations:
  9. deployment.kubernetes.io/revision: '1'
  10. kubesphere.io/creator: admin
  11. kubesphere.io/description: 监控使用
  12. spec:
  13. replicas: 1
  14. selector:
  15. matchLabels:
  16. app: redis-exporter
  17. template:
  18. metadata:
  19. labels:
  20. app: redis-exporter
  21. annotations:
  22. kubesphere.io/containerSecrets: '{"container-zsbagq":"harbor"}'
  23. spec:
  24. containers:
  25. - name: container-zsbagq
  26. image: 'ip:8888/monitor/redis_exporter:latest'
  27. args:
  28. - '-redis.addr'
  29. - 'redis-hip-redis-cluster-headless.hip-mid:6379'
  30. - '-redis.password'
  31. - '111111'
  32. ports:
  33. - name: tcp-9121
  34. containerPort: 9121
  35. protocol: TCP
  36. imagePullPolicy: IfNotPresent
  37. restartPolicy: Always
  38. imagePullSecrets:
  39. - name: harbor

3、创建serviceMonitor

  1. apiVersion: monitoring.coreos.com/v1
  2. kind: ServiceMonitor
  3. metadata:
  4. labels:
  5. app: redis-exporter
  6. name: redis-exporter
  7. namespace: devops
  8. spec:
  9. endpoints:
  10. - interval: 30s
  11. port: tcp-9121
  12. params:
  13. target:
  14. - redis-hip-redis-cluster-headless.hip-mid:6379
  15. relabelings:
  16. - sourceLabels: [__param_target]
  17. targetLabel: instance
  18. selector:
  19. matchLabels:
  20. app: redis-exporter
  21. namespaceSelector:
  22. matchNames:
  23. - devops

创建成功,访问prometheus targets界面,显示如图

4、告警规则

获取规则:

kubectl get prometheusrules prometheus-k8s-rules -n {namespace} -o yaml > prometheus-rule.yaml

  1. - name: redis_alters
  2. rules:
  3. - alert: redis_exporter_status
  4. annotations:
  5. description: job-{{$labels.job}}, instance-{{ $labels.instance }} 监控exporter下线,请检查!
  6. summary: 监控exporter下线预警
  7. expr: up{namespace="monitor",instance=~".*:9122"} == 0
  8. for: 3m
  9. labels:
  10. severity: emergency
  11. - alert: redis_status
  12. annotations:
  13. description: job-{{$labels.job}}, instance-{{ $labels.instance }} 节点下线,请检查!
  14. summary: 节点下线预警
  15. expr: redis_up{namespace="monitor"} == 0
  16. for: 3m
  17. labels:
  18. severity: emergency
  19. - alert: redis_memory_usage
  20. annotations:
  21. description: job-{{$labels.job}}, instance-{{ $labels.instance }} 内存超过90%,请检查!
  22. summary: 内存预警
  23. expr: redis_memory_used_bytes{namespace="monitor"} / redis_memory_max_bytes{namespace="monitor"}
  24. * 100 > 90
  25. for: 15s
  26. labels:
  27. severity: emergency
  28. - alert: redis_rejected_connection
  29. annotations:
  30. description: job-{{$labels.job}}, instance-{{ $labels.instance }} 一些连接被拒绝,请检查!
  31. summary: 连接被拒绝
  32. expr: increase(redis_rejected_connections_total{namespace="monitor"}[1m]) >
  33. 0
  34. for: 1m
  35. labels:
  36. severity: emergency
  37. - alert: redis_max_client
  38. annotations:
  39. description: job-{{$labels.job}}, instance-{{ $labels.instance }} 连接总数达到总量的90%,请检查!
  40. summary: 连接数过多
  41. expr: redis_connected_clients{namespace="monitor"} > redis_config_maxclients{namespace="monitor"}
  42. * 0.90
  43. for: 15s
  44. labels:
  45. severity: emergency

更新规则:

kubectl replace -f prometheus-rule.yaml

5、grafana模板

id:17507

关联文章:

【prometheus-operator】k8s监控集群外redis

以上内容对您有帮助,请点赞支持,谢谢!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/304776?site
推荐阅读
相关标签
  

闽ICP备14008679号