When using Redis, you need to monitor its running status to know whether it runs normally and troubleshoot its faults. TMP provides an exporter to monitor Redis and offers an out-of-the-box Grafana monitoring dashboard for it. This document describes how to use TMP to monitor Redis.
Note:For easier export installation and management, we recommend you use TKE for unified management.
password
. Below is a sample YAML configuration:apiVersion: v1
kind: Secret
metadata:
name: redis-secret-test
namespace: redis-test
type: Opaque
stringData:
password: you-guess # Corresponding Redis password
On the Deployment management page, click Create and select the target namespace to deploy the service. You can create in the console. Here, YAML is used to deploy the exporter. Below is a sample YAML configuration:
Note:For more information on the detailed exporter parameters, please see redis_exporter.
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
k8s-app: redis-exporter # Rename the exporter based on the business needs. We recommend you add the Redis instance information
name: redis-exporter # Rename the exporter based on the business needs. We recommend you add the Redis instance information
namespace: redis-test
spec:
replicas: 1
selector:
matchLabels:
k8s-app: redis-exporter # Rename the exporter based on the business needs. We recommend you add the Redis instance information
template:
metadata:
labels:
k8s-app: redis-exporter # Rename the exporter based on the business needs. We recommend you add the Redis instance information
spec:
containers:
- env:
- name: REDIS_ADDR
value: ip:port # `ip:port` of the corresponding Redis instance
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: redis-secret-test
key: password
image: ccr.ccs.tencentyun.com/redis-operator/redis-exporter:1.12.0
imagePullPolicy: IfNotPresent
name: redis-exporter
ports:
- containerPort: 9121
name: metric-port # This name is required during scrape task configuration
securityContext:
privileged: false
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
imagePullSecrets:
- name: qcloudregistrykey
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
curl
command with the address exposed by the exporter in the command line window, and you can get the corresponding Redis metrics normally. If no corresponding data is returned, please check whether REDIS_ADDR
and REDIS_PASSWORD
are correct as shown below:curl localhost:9121/metrics
The command execution result is as shown below:Pod Monitor
to define a Prometheus scrape task. Below is a sample YAML configuration:apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
name: redis-exporter # Enter a unique name
namespace: cm-prometheus # The namespace is fixed. Do not change it
spec:
podMetricsEndpoints:
- interval: 30s
port: metric-port # Enter the name of the corresponding port of the Prometheus exporter in the Pod YAML configuration file
path: /metrics # Enter the value of the corresponding path of the Prometheus exporter. If it is not specified, it will be `/metrics` by default
relabelings:
- action: replace
sourceLabels:
- instance
regex: (.*)
targetLabel: instance
replacement: 'crs-xxxxxx' # Change it to the corresponding Redis instance ID
- action: replace
sourceLabels:
- instance
regex: (.*)
targetLabel: ip
replacement: '1.x.x.x' # Change it to the corresponding Redis instance IP
namespaceSelector: # Select the namespace where the Pod to be monitored resides
matchNames:
- redis-test
selector: # Enter the label value of the Pod to be monitored to locate the target Pod
matchLabels:
k8s-app: redis-exporter
Note:As the exporter and Redis are deployed on different servers, we recommend you use the Prometheus relabeling mechanism to add the Redis instance information to the monitoring metrics so as to locate problems more easily.
Was this page helpful?