6

Prometheus学习笔记–Prometheus 监控之 Redis |坐而言不如起而行! 二丫讲梵

 3 years ago
source link: http://www.eryajf.net/2497.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
本文预计阅读时间 6 分钟

prometheus监控redis需要用到redis_exporter。

redis_exporter 项目地址:https://github.com/oliver006/redis_exporter

1、安装部署

我这里的redis部署在192.168.111.11之上,而prometheus服务端是在192.168.111.3上,这个时候,监控的工具redis_exporter可以部署在这两台主机任一一台上,只不过需要注意的是,在配置prometheus.yaml添加监控目标的时候,注意填写对应ip即可。

我这里则部署在了Prometheus Server之上。

  1. $ cd /usr/local/src
  2. $ wget https://github.com/oliver006/redis_exporter/releases/download/v0.21.2/redis_exporter-v0.21.2.linux-amd64.tar.gz
  3. $ mkdir /usr/local/redis_exporter
  4. $ tar xf redis_exporter-v0.21.2.linux-amd64.tar.gz -C /usr/local/redis_exporter/

2、redis_exporter 用法

解压后只有一个二进制程序就叫 redis_exporter 通过 -h 可以获取到帮助信息,下面列出一些常用的选项:

  1. -redis.addr:指明一个或多个 Redis 节点的地址,多个节点使用逗号分隔,默认为 redis://localhost:6379
  2. -redis.password:验证 Redis 时使用的密码;
  3. -redis.file:包含一个或多个redis 节点的文件路径,每行一个节点,此选项与 -redis.addr 互斥。
  4. -web.listen-address:监听的地址和端口,默认为 0.0.0.0:9121

3,运行 redis_exporter 服务

1,方式A直接启动。

  1. ## 无密码
  2. ./redis_exporter redis//192.168.111.11:6379 &
  3. ## 有密码
  4. redis_exporter -redis.addr 192.168.111.11:6379 -redis.password 123456

2,方式B通过system管理。

创建 redis_exporter.service 启动脚本

  1. $ vim /usr/lib/systemd/system/redis_exporter.service
  2. [Unit]
  3. Description=redis_exporter
  4. Documentation=https://github.com/oliver006/redis_exporter
  5. After=network.target
  6. [Service]
  7. Type=simple
  8. User=prometheus
  9. ExecStart=/usr/local/redis_exporter/redis_exporter -redis.addr 192.168.111.11:6379 -redis.password 123456
  10. Restart=on-failure
  11. [Install]
  12. WantedBy=multi-user.target

注意:关于redis的相关信息,则在ExecStart配置项当中进行定义!

redis_exporter 使用 prometheus 用户运行,所以需要创建该用户:

  1. $ groupadd prometheus
  2. $ useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus

启动服务:

  1. $ systemctl daemon-reload
  2. $ systemctl start redis_exporter
  3. $ systemctl status redis_exporter
  4. $ ss -tnl|grep 9121

4、配置 prometheus.yml 添加监控目标

  1. $ vim /usr/local/prometheus/prometheus.yml
  2. - job_name: 'redis'
  3. scrape_interval: 10s
  4. static_configs:
  5. - targets:
  6. - ['localhost:9121'] #如果是部署在192.168.111.11上,那么localhost需要改成192.168.111.11

重启服务。

  1. $ systemctl restart prometheus

5,配置 Grafana 的模板

redis_exporter 在 Grafana 上为我们提供好了 Dashboard 模板:https://grafana.com/dashboards/763

下载后在 Grafana 中导入 json 模板就可以看到官方这样的示例截图啦:

参考:https://codegreen.cn/2018/09/29/prometheus-redis/


weinxin


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK