prometheus监控redis集群

【1】利用 redis_exporter 监控 redis 集群

(1.0)redis_exporter

以前都是用傻办法,一个实例一个采集器;

redis_exporter 支持的参数很多,对我们有用的就几个。

./redis_exporter --help
Usage of ./redis_exporter:
    -redis.addr string
        Address of the Redis instance to scrape (default "redis://localhost:6379")
    -redis.password string
        Password of the Redis instance to scrape
    -web.listen-address string
        Address to listen on for web interface and telemetry. (default ":9121")

本来想采取最low 的方法,一个实例启一个 redis_exporter。这样子的话,集群那里很多语句都用不了,比如 cluster_slot_fail。放弃该方法

nohup ./redis_exporter -redis.addr 172.18.11.139:7000  -redis.password xxxxxx  -web.listen-address 172.18.11.139:9121 > /dev/null 2>&1 &
nohup ./redis_exporter -redis.addr 172.18.11.139:7001  -redis.password xxxxxx  -web.listen-address 172.18.11.139:9122 > /dev/null 2>&1 &
nohup ./redis_exporter -redis.addr 172.18.11.140:7002  -redis.password xxxxxx  -web.listen-address 172.18.11.139:9123 > /dev/null 2>&1 &
nohup ./redis_exporter -redis.addr 172.18.11.140:7003  -redis.password xxxxxx  -web.listen-address 172.18.11.139:9124 > /dev/null 2>&1 &
nohup ./redis_exporter -redis.addr 172.18.11.141:7004  -redis.password xxxxxx  -web.listen-address 172.18.11.139:9125 > /dev/null 2>&1 &
nohup ./redis_exporter -redis.addr 172.18.11.141:7005  -redis.password xxxxxx  -web.listen-address 172.18.11.139:9126 > /dev/null 2>&1 &

(1.1)redis集群情况

#redis集群IP和端口,集群配置了密码

136.xxx.102.112:7000
136.xxx.102.112:7001
136.xxx.102.112:7002
136.xxx.102.113:7000
136.xxx.102.113:7001
136.xxx.102.113:7002

(1.2)redis_exporter部署,配置prometheus

#将文件解压并修改文件夹名称,插件不一定安装redis端

tar -zxvf redis_exporter-v1.3.5.linux-amd64.tar.gz
mv redis_exporter-v1.3.5.linux-amd64 redis_exporter

修改prometheus配置,注意文件格式,如果文件有问题会导致prometheus无法启动

vi prometheus.yml

#将文件解压并修改文件夹名称,插件不一定安装redis端
tar -zxvf redis_exporter-v1.3.5.linux-amd64.tar.gz
mv redis_exporter-v1.3.5.linux-amd64 redis_exporter
#修改prometheus配置,注意文件格式,如果文件有问题会导致prometheus无法启动
vi prometheus.yml
  - job_name: 'redis_exporter_targets'
    static_configs:
      - targets:
        - redis://136.127.102.112:7000
        - redis://136.127.102.112:7001
        - redis://136.127.102.112:7002
        - redis://136.127.102.113:7000
        - redis://136.127.102.113:7001
        - redis://136.127.102.113:7002
    params:
      check-keys: ["metrics:*"]
    metrics_path: /scrape
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 136.127.102.112:9122
  - job_name: 'redis_exporter'
    static_configs:
      - targets:
        - 136.127.102.112:9122

 

相关参考:

其实官方文档已经写了。

scrape_configs:
  ## config for the multiple Redis targets that the exporter will scrape
  - job_name: 'redis_exporter_targets'
    static_configs:
      - targets:
        - redis://first-redis-host:6379
        - redis://second-redis-host:6379
        - redis://second-redis-host:6380
        - redis://second-redis-host:6381
    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-HOSTNAME>>:9121
  
  ## config for scraping the exporter itself
  - job_name: 'redis_exporter'
    static_configs:
      - targets:
        - <<REDIS-EXPORTER-HOSTNAME>>:9121

 

(1.3)采集器(探针)启动

#启动探针,因为是集群只需要写清楚密码即可,默认监听端口为9121,由于有密码需要将端口设置为9122
nohup ./redis_exporter -redis.password passwd123 -web.listen-address 0.0.0.0:9122 &
#prometheus需要重启 或者 reload 重载

(1.4)效果

  

 

 

 

【参考文档】

转自:https://blog.csdn.net/weixin_43135696/article/details/122258105

posted @ 2022-07-20 11:58  郭大侠1  阅读(952)  评论(0编辑  收藏  举报