一、实验方式
- 使用sidecar模式运行reids+redis-exporter
- prometheus中添加redis的抓取任务
- web页面查看
二、创建reids及redis-exporter
cat prome-redis.yaml apiVersion: apps/v1 kind: Deployment metadata: name: redis namespace: monitoring #此处与prometheus在同一命名空间 spec: replicas: 1 selector: matchLabels: app: redis template: metadata: annotations: prometheus.io/scrape: "true" prometheus.io/port: "9121" labels: app: redis spec: containers: - name: redis image: redis:4 resources: requests: cpu: 100m memory: 100Mi ports: - containerPort: 6379 - name: redis-exporter image: oliver006/redis_exporter:latest resources: requests: cpu: 100m memory: 100Mi ports: - containerPort: 9121--- kind: Service apiVersion: v1 metadata: name: redis namespace: monitoring spec: selector: app: redis ports: - name: redis port: 6379 targetPort: 6379 - name: prom port: 9121 targetPort: 9121
三、添加redis的抓取任务
cat prometheus-redis.yaml - job_name: 'redis' static_configs: - targets: ['redis:9121'] 将文件制作成secret挂载到prometheus kubectl create secret generic prometheus-redis --from-file=prometheus-redis.yaml -n monitoring 在 prometheus-prometheus.yaml 中增加以下内容 additionalScrapeConfigs: #增加scrape-config配置 name: prometheus-redis key: prometheus-redis.yaml