我们使用Prometheus + Redis Exporter来实现对Redis的监控;由于采集数据本身时不占用资源,如果每一个Redis Server都使用一个Exporter,则会造成资源的严重浪费;
针对以下问题:
1. Redis本身有密码,避免密码的明文传输,将密码信息采用Apollo进行管理
2. 需要支持动态传入需要监控的Redis
3. 公用同一个Redis Exporter
所以,我们针对Redis Exporter做了如下简单的调整;
监控调整:
具体部署设置:
第一步: 先配置Apollo:
将需要监控的Redis密码信息配置到Apollo中【如果没有密码,可以不用进行配置】
{ "redis://a.abc.com:6385": "password", "redis://a.abc.com:6378": "", "redis://a.abc.com:6379": "" }
第二步: 部署Redis Exporter [部署在k8s中]
--- apiVersion: extensions/v1beta1 kind: Deployment metadata: namespace: monitoring-redis name: "redis-one-multi" labels: name: redis-one-multi spec: replicas: 3 selector: matchLabels: name: redis-one-multi template: metadata: labels: name: redis-one-multi spec: containers: - name: redis-one-multi image: " #harbor/image/redis_exporter:v1.5.9" command: - /redis_exporter args: - --redis.addr="" - --redis-only-metrics env: - name: APOLLO_CONFIG_SERVER value: "http://apollo-config.system-service.domain.com" - name: APP_ID value: "redis-exporter-go" - name: APOLLO_CLUSTER value: "default" - name: APOLLO_NS_CONFIG value: "redis-pwd.json" resources: requests: cpu: 1000m memory: 1024Mi limits: cpu: 1000m memory: 1024Mi ports: - name: http containerPort: 9121
第三步:针对监控的Redis Server指定
## config for the multiple Redis targets that the exporter will scrape - job_name: 'redis_exporter_targets' metrics_path: /scrape scrape_interval: '15s' scrape_timeout: '15s' scheme: 'http' static_configs: - targets: - redis://a.abc.com:6385 - redis://a.abc.com:6378 - redis://a.abc.com:6379 relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - target_label: __address__ replacement: 127.0.0.1:9121
【自我检测】
通过http请求时,会根据target到配置文件中匹配到密码,进行请求; http://localhost:9121/scrape?target=redis://a.abc.com:6385
项目介绍: