kube-prometheus 监控 redis部署

1. 使用ansible 建立一个redis 实例

 

 

 
2. 部署redis_exporter 
docker版部署 

docker run -d --name redis_exporter -e REDIS_ADDR="redis://192.168.20.157:6379"  -e REDIS_PASSWORD='Senfffc.yl' -p 9121:9121  oliver006/redis_exporter


二进制部署

wget https://github.com/oliver006/redis_exporter/releases/download/v1.12.1/redis_exporter-v1.12.1.linux-amd64.tar.gz

tar -zxvf   redis_exporter-v1.12.1.linux-amd64.tar.gz

./redis_exporter -redis.addr=192.168.20.157:6379  -redis.password='Senfffc.yl'  -web.listen-address=192.168.20.157:9121

 

注意 密码中有点 等特殊字符, 需要使用 '' .

三 访问:

 

 

5. 在k8s上,新建 endpoint  service   servicemonitor

cat redis-monitor.yaml 

apiVersion: v1
kind: Endpoints
metadata:
  name: redis-metrics
  namespace: monitoring
  labels:
    k8s-app: redis-metrics
subsets:
- addresses:
    - ip: 192.168.20.157
  ports:
  - name: redis-exporter
    port: 9121
    protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
  name: redis-metrics
  namespace: monitoring
  labels:
    k8s-app: redis-metrics
spec:
  type: ClusterIP
  clusterIP: None
  ports:
  - name: redis-exporter
    port: 9121
    protocol: TCP
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: redis-metrics
  namespace: monitoring
  labels:
    app: redis-metrics
    k8s-app: redis-metrics
    prometheus: kube-prometheus
    release: kube-prometheus
spec:
  endpoints:
  - port: redis-exporter
    interval: 15s
  selector:
    matchLabels:
      k8s-app: redis-metrics
  namespaceSelector:
    matchNames:
    - monitoring

 

 6. k8s 执行 yaml文件

kubectl create -f  redis-monitor.yaml

 

7. granfana 配置

 

 

导入 模版:https://grafana.com/grafana/dashboards?search=kubernetes

 

 

 

显示: 

 

 

posted @ 2020-10-23 15:38  fengjian1585  阅读(663)  评论(0编辑  收藏  举报