Prometheus监控Redis

文章详细介绍了如何下载和使用redis_exporter来监控Redis实例,通过systemd管理服务,配置Prometheus进行动态发现并设置scrape_interval,以及在Grafana中创建dashboard进行可视化展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1 下载redis exporter

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

2 systemd 管理redis exporter

service文件: /usr/lib/systemd/system/redis_exporter.service

[Unit]
Description=redis_exporter
Documentation=https://github.com/oliver006/redis_exporter/
After=network.target

[Service]
ExecStart=/usr/local/src/redis_exporter/redis_exporter -redis.addr 172.16.53.130:16379 -redis.password gs2020gsGXGD
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure


[Install]
WantedBy=multi-user.target

[Unit]
Description=redis_exporter
After=network.target

redis_exporter参数:

# ./redis_exporter --help
......
  -redis.addr string
        Address of the Redis instance to scrape (default "redis://localhost:6379")
  -redis.password string
        Password of the Redis instance to scrape
  -redis.password-file string
        Password file of the Redis instance to scrape
  -redis.user string
        User name to use for authentication (Redis ACL for Redis 6.0 and newer)
......
  -web.listen-address string
        Address to listen on for web interface and telemetry. (default ":9121")
  -web.telemetry-path string
        Path under which to expose metrics. (default "/metrics")

3 启动exporter

systemctl start redis_exporter.service

systemctl stop redis_exporter.service

systemctl enable redis_exporter.service

4 prometheus动态发现

prometheus.yml

  - job_name: 'redis_monitor'
    scrape_interval: 1m
    file_sd_configs:
     - files:
        - /usr/local/src/prometheus/conf.d/redis.json
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 172.16.53.117:9121 #部署redis_exporter的地址

redis.json

[
  {
    "labels": {
      "desc": "redis",
      "group": "redis",
      "host_ip": "172.16.53.117"
    },
    "targets": [
      "redis://172.16.53.130:16379",
      "redis://172.16.53.130:16380",
      "redis://172.16.53.127:16379",
      "redis://172.16.53.127:16380",
      "redis://172.16.53.126:16379",
      "redis://172.16.53.126:16380"
    ]
  }
]

5 Grafana dashboard

ID:11835

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值