Using redis exporter to monitor the performance of redis cluster

There are three modes of redis cluster: master-slave, sentinel and cluster. About the introduction and deployment of these three modes, other articles also have related introduction. I have completed the deployment of the three modes with reference to other blogs, and the blog address is in the comment area.
At present, redis uses the master-slave mode. The cluster information is as follows:

[root@master redis]# redis-cli -h 192.168.122.7 -a 123456 info replication
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.122.8,port=6379,state=online,offset=28,lag=0
slave1:ip=192.168.122.9,port=6379,state=online,offset=28,lag=1
master_replid:950b3c2b60b56148577e566ac53af00911527c4e
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:28
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:28
[root@master redis]#
[root@master ~]#

As can be seen from the above information, at this time, the cluster is the primary and secondary mode, 192.168.122.7 is the master node, 192.168.122.8 and 192.168.122.9 are the slave nodes. There are many related articles about the specific operation of redis. The following steps are how to use redis exporter to collect redis performance monitoring.

1 create redis exporter

Create a Deployment of redis exporter using the following yaml file‘

[root@master redis-local]# cat redis-exporter.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis-exporter001
  namespace: monitoring
  labels:
    k8s-app: redis-exporter001
spec:
  selector:
    matchLabels:
      k8s-app: redis-exporter001
  template:
    metadata:
      labels:
        k8s-app: redis-exporter001
    spec:
      containers:
      - name: redis-exporter001
        image: oliver006/redis_exporter:latest
        args: ["-redis.addr", "redis://192.168.122.7:6379", "-redis.password", "123456"]
        ports:
        - containerPort: 9121
          name: http
[root@master redis-local]# kubectl apply -f redis-exporter.yaml
deployment.apps/redis-exporter001 created
[root@master redis-local]# kubectl logs -f -n monitoring redis-exporter001-5dc78569b5-5lmtf
time="2020-05-26T02:49:21Z" level=info msg="Redis Metrics Exporter v1.6.1    build date: 2020-05-13-02:16:26    sha1: 34c779deb5f9a1e023166b5cf3717d53cdc97053    Go: go1.14.2    GOOS: linux    GOARCH: amd64"
time="2020-05-26T02:49:21Z" level=info msg="Providing metrics at :9121/metrics"

At this time, the redis exporter is created

2. Create redis exporter service

Use the following yaml file to create the redis exporter service

[root@master redis-local]# cat redis-exporter-service.yaml
apiVersion: v1
kind: Service
metadata:
  labels:
    k8s-app: redis-exporter001
  name: redis-exporter001
  namespace: monitoring
spec:
  type: NodePort
  ports:
  - name: http
    port: 9121
    nodePort: 30019
    targetPort: http
  selector:
    k8s-app: redis-exporter001
[root@master redis-local]# kubectl apply -f redis-exporter-service.yaml
service/redis-exporter001 created
[root@master redis-local]# kubectl describe svc -n monitoring redis-exporter001
Name:                     redis-exporter001
Namespace:                monitoring
Labels:                   k8s-app=redis-exporter001
Annotations:              kubectl.kubernetes.io/last-applied-configuration:
                            {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"k8s-app":"redis-exporter001"},"name":"redis-exporter001","name...
Selector:                 k8s-app=redis-exporter001
Type:                     NodePort
IP:                       10.10.126.113
Port:                     http  9121/TCP
TargetPort:               http/TCP
NodePort:                 http  30019/TCP
Endpoints:                10.124.187.225:9121
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>
[root@master redis-local]#

use nodeip:nodeport Visit

At this time, the metrics deployment of redis is complete

3. Create redis exporter servermonitor

Use the following file to create the redis exporter servermonitor

[root@master redis-local]# cat redis-exporter-serviceMonitor.yaml
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  labels:
    k8s-app: redis-exporter001
  name: redis-exporter001
  namespace: monitoring
spec:
  endpoints:
  - interval: 30s
    port: http
  jobLabel: k8s-app
  selector:
    matchLabels:
      k8s-app: redis-exporter001
[root@master redis-local]# kubectl apply -f redis-exporter-serviceMonitor.yaml
servicemonitor.monitoring.coreos.com/redis-exporter001 created
[root@master redis-local]# kubectl describe servicemonitors.monitoring.coreos.com -n monitoring redis-exporter001
Name:         redis-exporter001
Namespace:    monitoring
Labels:       k8s-app=redis-exporter001
Annotations:  kubectl.kubernetes.io/last-applied-configuration:
                {"apiVersion":"monitoring.coreos.com/v1","kind":"ServiceMonitor","metadata":{"annotations":{},"labels":{"k8s-app":"redis-exporter001"},"na...
API Version:  monitoring.coreos.com/v1
Kind:         ServiceMonitor
Metadata:
  Creation Timestamp:  2020-05-26T02:53:46Z
  Generation:          1
  Resource Version:    574501
  Self Link:           /apis/monitoring.coreos.com/v1/namespaces/monitoring/servicemonitors/redis-exporter001
  UID:                 065dc9cc-a872-4630-a387-f4b11193aab6
Spec:
  Endpoints:
    Interval:  30s
    Port:      http
  Job Label:   k8s-app
  Selector:
    Match Labels:
      k8s-app:  redis-exporter001
Events:         <none>

Finally, create a serviceaccount

[root@master yaml]# kubectl create serviceaccount -n monitoring redis-exporter001
serviceaccount/redis-exporter001 created

After the above deployment is completed, check the corresponding targets in the prometheus page

4. Create a dashboard on the grafana panel to monitor the redis cluster



Click Import

The monitoring effect is shown in the figure above

5. Redis writes data for testing

[root@master redis-local]# cat 123.txt |redis-cli -h 192.168.122.7 -a 123456


Insert data in batches and view the grafana monitoring

At this time, the performance utilization rate of redis is increasing.
How to monitor the redis Cluster -- master-slave mode. As for how to monitor the other two modes, subsequent documents will continue to update.

Tags: Operation & Maintenance Redis Kubernetes SHA1 Linux

Posted on Tue, 26 May 2020 04:52:09 -0700 by rawb