首页 公告 项目 RSS

使用prometheus监控redis

August 31, 2021 本文有 256 个字 需要花费 1 分钟阅读

简介

今天水一波

项目地址

https://github.com/oliver006/redis_exporter

操作

首先拉取镜像

docker pull oliver006/redis_exporter:v1.27.0-alpine

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

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
---
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
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