监控redis

1,在redis机器上安装redis_exporter

  • 下载,安装redis_exporter
https://prometheus.io/docs/instrumenting/exporters/#databases
tar -xf redis_exporter-v1.50.0.linux-amd64.tar.gz
  • 启动redis_exporter
#直接启动,无密码
./redis_exporter redis//172.16.0.9:6379 &
./redis_exporter -redis.addr 172.18.11.138:6379 -redis.password xxxxx &
#有密码
redis_exporter -redis.addr 172.16.0.9:6379 -redis.password 123456

#systemctl启动
vim /usr/lib/systemd/system/redis_exporter.service

[Unit]
Description=redis_exporter
Documentation=https://github.com/oliver006/redis_exporter
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/opt/monitor/redis_exporter/redis_exporter -redis.addr 172.18.2.35:6488
Restart=on-failure
[Install]
WantedBy=multi-user.target

systemctl start redis_exporter

#添加一个redis地址和端口即可所有所有节点数据

2,配置prometheus配置文件

vim prometheus.yaml

  - job_name: 'redis_exporter_targets'
    static_configs:
      - targets:
        - redis://192.18.3.34:7000
        - redis://192.18.3.34:7001
        - redis://192.18.3.35:7002
        - redis://192.18.3.35:7003
        - redis://192.18.3.36:7004
        - redis://192.18.3.36:7005
    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: 172.18.2.35:9121
  - job_name: 'redis_exporter'
#    scrape_interval: 10s
    static_configs:
      - targets:
        - 172.18.2.35:9121

systemctl start prometheus

#replacement:redis_exporter所在机器的ip

3,设置redis maxmemory

vim redis.conf

maxmemory 128M

./bin/redis-cli -h 172.18.2.36 -p 7005 -a 123
CONFIG set  maxmemory 128M

#默认maxmemory为0,意思为不限制内存使用。

4,导入redis监控模板736

prometheus监控redis集群并显示到granfana面板-LMLPHP

prometheus监控redis集群并显示到granfana面板-LMLPHP
prometheus监控redis集群并显示到granfana面板-LMLPHP
查看granfana监控面板
prometheus监控redis集群并显示到granfana面板-LMLPHP

完成prometheus监控redis

05-17 17:11