使用prometheus监控redis

简介

今天水一波

项目地址

https://github.com/oliver006/redis_exporter

操作

首先拉取镜像

docker pull oliver006/redis_exporter:v1.27.0-alpine

之后编写deployment,servicemonitor,还有service。如下

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis-exporter
  namespace: monitoring
  labels:
    app.kubernetes.io/name: redis-exporter
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: redis-exporter
  template:
    metadata:
      labels:
        app.kubernetes.io/name: redis-exporter
    spec:
      imagePullSecrets:
      - name: regcred
      containers:
      - name: redis-exporter
        image: registry.bboysoul.cn/redis_exporter:v1.27.0-alpine
        resources:
          limits:
            memory: "128Mi"
            cpu: "500m"
        env:
          - name: REDIS_ADDR
            value: ""
          - name: REDIS_PASSWORD
            value: ""
        ports:
        - containerPort: 9121
          name:  redis-exporter
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
---
apiVersion: v1
kind: Service
metadata:
  name: redis-exporter
  namespace: monitoring
  labels:
    app.kubernetes.io/name: redis-exporter
spec:
  type: ClusterIP
  selector:
    app.kubernetes.io/name: redis-exporter
  ports:
  - port: 9121
    targetPort: 9121
    name: redis-exporter
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  labels:
    app.kubernetes.io/name: redis-exporter
  name: redis-exporter
  namespace: monitoring
spec:
  endpoints:
  - interval: 30s
    port: redis-exporter
    scheme: http
  selector:
    matchLabels:
      app.kubernetes.io/name: redis-exporter

主义servicemonitor和service的label一定要匹配上

下面是grafana的dashboard

https://grafana.com/grafana/dashboards/763

导入就好

欢迎关注我的博客 www.bboy.app

Have Fun