Prometheus监控Redis集群

来自linux中国网wiki
跳到导航 跳到搜索


pre

Monitoring with prometheus


Prometheus 监控 Redis cluster,其实套路都是一样的,使用 exporter。 exporter 负责采集指标,通过 http 暴露给 Prometheus 拉取。granafa 则通过这些指标绘图展示数据。Prometheus 收集的数据还会根据你设置的告警规则判断是否要发送给 Alertmanager, Alertmanager 则要判断是否要发出告警。

Alertmanager 告警分为三个阶段

   Inactive 触发告警的规则会被发送到这来。
   Pending 你设置的等待时间,即规则里面的 for
   Firing 发送告警到邮件、钉钉之类的

* redis_exporter

** redis_exporter from binary

解压而已  

#is me 如果不同一台机器 也是只跑一个 node  加上所以的IP on prometheus.yml就行了呢
./redis_exporter -redis.addr  192.168.10.193:7000 -redis.password 3passd123yui  -web.listen-address  192.168.10.193:9121

./redis_exporter -redis.addr  192.168.10.193:7000 -redis.password 3passd123yui  -web.listen-address  192.168.10.193:9121


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 &


-redis.addr string
-redis.password
nohup ./redis_exporter -redis.password xxxxx  &


# 这些看起来 监听内网IP 其它在外网 开了防火墙还是可以通的呢 

#启动文件
cat  /usr/lib/systemd/system/redis-exporter.service
[Unit]
Description=prometheus  redis  exporter
After=network.target

[Service]
Type=simple
Restart=on-failure
ExecStart=/data/mon/redis_exporter/redis_exporter \
-redis.addr 172.31.22.218:7000 \
-redis.password hpllopasswD9923   \
-web.listen-address 172.31.22.218:9121


[Install]
WantedBy=multi-user.target


systemctl daemon-reload#记得加x
systemctl enable   redis-exporter.service
systemctl start   redis-exporter.service


https://github.com/oliver006/redis_exporter/releases/download/v1.5.3/redis_exporter-v1.5.3.linux-amd64.tar.gz

https://github.com/oliver006/redis_exporter/releases/

**ins redis_exporter using docker

https://hub.docker.com/r/oliver006/redis_exporter

** prome conf

#这个成功的单机配置 记得要 '' 全部当str
  - job_name: 'redis'
    static_configs:
      - targets: ['192.168.11.125:9121']




#暂时可以在prome 出数据的redis cluster 
#scrape_configs:
  - job_name: 'redis_cluster'
    scrape_interval: 10s
    static_configs:
      #- targets: ['192.168.11.125:9121']
  ## config for the multiple Redis targets that the exporter will scrape
  #  - job_name: 'redis_exporter_targets'
  #  static_configs:
      - targets:
        - redis://192.168.10.193:7000
        - redis://192.168.10.193:7001
        - redis://192.168.10.193:7002
        - redis://192.168.10.193:7003
        - redis://192.168.10.193:7004
        - redis://192.168.10.193:7005
    metrics_path: /scrape
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 192.168.10.193:9121

http://192.168.10.144:9090/graph?g0.range_input=1h&g0.expr=redis_cluster_state&g0.tab=1

graph 输入下面的 命令 
redis_cluster_state

#for market 
#scrape_configs:
  - job_name: 'market_redis_cluster'
    static_configs:
      #- targets: ['192.168.11.125:9121']
  ## config for the multiple Redis targets that the exporter will scrape
  #  - job_name: 'redis_exporter_targets'
  #  static_configs:
      - targets:
        - redis://10.3.10.141:7000
        - redis://10.3.10.141:7001
        - redis://10.3.10.142:7002
        - redis://10.3.10.142:7003
        - redis://10.3.10.143:7004
        - redis://10.3.10.143:7005
    metrics_path: /scrape
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 10.3.10.142:9121

err

现在 外网能telnet 通 hello的 redis 端口  不过  prometheus  那里还是 0


记得要用 dos2unix 去格式化一下 不然配置很容易出错的  yml

0 err="error loading config from \"/etc/prometheus/prometheus.yml\": couldn't load configuration (--config.file=\"/etc/prometheus/prometheus.yml\"): parsing YAML file /etc/prometheus/prometheus.yml: yaml: line 47: did not find expected key"


* grafana 模板

~/prometheus/redis_mon.yml 

有个 763 也是不错呢

  • 如果client export 那边服务没起来 是跑不动 9090的 例如 昨天加的mysql 没跑 今天加redis 完全打不开


  • redis 单机 版本

图形garafa 还不行 有空再看吧 https://yq.aliyun.com/articles/251478

* see also

Prometheus 监控Redis的正确姿势(redis集群)

prometheus监控redis

https://github.com/oliver006/redis_exporter

https://www.jianshu.com/p/fba020bf5716