美文网首页
prometheus监控redis(无metric接口)

prometheus监控redis(无metric接口)

作者: 慕知 | 来源:发表于2021-04-30 09:46 被阅读0次

https://github.com/oliver006/redis_exporter

1,部署一个测试环境

[root@\ k8s-m-01~]# mkdir redis
[root@\ k8s-m-01~]# cd redis/

[root@\ k8s-m-01~/redis]# vim deploymeng_redis.yaml
kind: Deployment
apiVersion: apps/v1
metadata:
  name: redis
spec:
  selector:
    matchLabels:
      k8s: redis-exporter
  template:
    metadata:
      labels:
        k8s: redis-exporter
    spec:
      containers:
        - name: redis
          imagePullPolicy: IfNotPresent
          image: redis
---
kind: Service
apiVersion: v1
metadata:
  name: redis-svc
  labels:
    k8s: redis-exporter
spec:
  ports:
    - port: 6379
      targetPort: 6379
      name: redis
  selector:
    k8s: redis-exporter





[root@\ k8s-m-01~/redis]# kubectl get pods
NAME                                        READY   STATUS    RESTARTS   AGE
redis-6b9dd9c556-2dllt                      1/1     Running   0          49s


[root@\ k8s-m-01~/redis]# kubectl get deployments.apps 
NAME                        READY   UP-TO-DATE   AVAILABLE   AGE
redis                       1/1     1            1           64s

2,部署expertor,从而创建一个metrics接口


[root@\ k8s-m-01~/redis]# vim exprter_redis.yaml
kind: Deployment
apiVersion: apps/v1
metadata:
  name: redis-exporter-server
spec:
  selector:
    matchLabels:
      k8s: redis-exporter-server
  template:
    metadata:
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "9121"
      labels:
        k8s: redis-exporter-server
    spec:
      containers:
        - name: redis
          image: oliver006/redis_exporter
          args:
            - "--redis.addr=redis://redis-svc.default.svc.cluster.local:6379"
          ports:
            - containerPort: 9121
---
kind: Service
apiVersion: v1
metadata:
  name: redis-exporter-server
  labels:
    k8s: redis-exporter-server-svc
spec:
  ports:
    - port: 9121
      targetPort: 9121
      name: redis-exporter
  selector:
    k8s: redis-exporter-server




[root@\ k8s-m-01~/redis]# kubectl apply -f exprter_redis.yaml 
deployment.apps/redis-exporter-server created
service/redis-exporter-server created

[root@\ k8s-m-01~/redis]# kubectl get svc
NAME                        TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)    AGE
redis-exporter-server       ClusterIP   10.111.0.77    <none>        9121/TCP   11s
redis-svc                   ClusterIP   10.111.17.45   <none>        6379/TCP   3m37s


[root@\ k8s-m-01~/redis]# kubectl get pods
NAME                                        READY   STATUS    RESTARTS   AGE
nginx-prometheus-exporter-86bc575bb-2mgh8   1/1     Running   0          44m
redis-6b9dd9c556-2dllt                      1/1     Running   0          3m43s
redis-exporter-server-6f6476f86f-dwbtq      1/1     Running   0          17s

3,创建ServiceMonitor,注入promethu


[root@\ k8s-m-01~/redis]# vim servicemonitor_redis.yaml
kind: ServiceMonitor
apiVersion: monitoring.coreos.com/v1
metadata:
  labels:
    app: redis-prometheus-exporter-servicemonitor
    deploy: redis-exporter-servicemonitor
  name: redis-monitor
  namespace: monitoring
spec:
  endpoints:
    - interval: 3s
      port: redis-exporter
  selector:
    matchLabels:
      k8s: redis-exporter-server-svc
  namespaceSelector:
    matchNames:
      - "default"




[root@\ k8s-m-01~/redis]# kubectl apply -f servicemonitor_redis.yaml 

[root@\ k8s-m-01~/redis]# kubectl get servicemonitor -n monitoring 
NAME                      AGE
... ...
redis-monitor             43s


4,检测

image.png image.png

5,增加grafana模板

增加grafana模板

6, 进入监控看大屏

插入刚刚官网的id号

7.监控页面

image.png

相关文章

网友评论

      本文标题:prometheus监控redis(无metric接口)

      本文链接:https://www.haomeiwen.com/subject/tgfgrltx.html