一 官方文档
redis-exporter的GitHub地址(包含部署参数、指标明细说明等):https://github.com/oliver006/redis_exporter
二 安装redis-exporter
通过一下yaml文件安装
kubectl apply -f redis-exporter-deployment.yaml
redis-exporter-deployment.yaml1
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57apiVersion: apps/v1
kind: Deployment
metadata:
name: redis-exporter-cluster
namespace: kube-system
labels:
k8s-app: redis-exporter-cluster
spec:
selector:
matchLabels:
k8s-app: redis-exporter-cluster
template:
metadata:
labels:
k8s-app: redis-exporter-cluster
spec:
containers:
- name: redis-exporter-cluster
image: oliver006/redis_exporter:v1.37.0
args: ["-redis.addr", "redis://10.0.43.243:6379,redis://10.0.43.244:6379,redis://10.0.43.245:6379,redis://10.0.43.246:6379,redis://10.0.43.247:6379,redis://10.0.43.248:6379"]
livenessProbe:
failureThreshold: 1
httpGet:
path: /health
port: 9121
scheme: HTTP
initialDelaySeconds: 3
periodSeconds: 30
successThreshold: 1
timeoutSeconds: 9
readinessProbe:
failureThreshold: 1
httpGet:
path: /health
port: 9121
scheme: HTTP
initialDelaySeconds: 3
periodSeconds: 15
successThreshold: 1
timeoutSeconds: 9
ports:
- containerPort: 9121
name: http
apiVersion: v1
kind: Service
metadata:
name: redis-exporter-cluster
namespace: kube-system
spec:
ports:
- name: http
port: 9121
protocol: TCP
selector:
k8s-app: redis-exporter-cluster
prometheus的configmap增加配置如下:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17- job_name: 'redis_cluser_targets'
static_configs:
- targets:
- redis://10.0.43.243:6379
- redis://10.0.43.244:6379
- redis://10.0.43.245:6379
- redis://10.0.43.246:6379
- redis://10.0.43.247:6379
- redis://10.0.43.248:6379
metrics_path: /scrape
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: redis-exporter-cluster:9121
再通过命令 curl -XPOST http://[prometheus-host]:9090/-/reload
刷新Prometheus配置。
如果不想在Prometheus中增加configmap配置,也可在redis-exporter的yaml文件中增加以下annotation,通过同一个k8s中部署的Prometheus的监控配置服务发现自动发现。1
2
3
4
5spec:
template:
metadata:
annotations:
prometheus.io/scrape: "true"