Prometheus系列--使用redis_exporter监控Redis
一、概述
Prometheus监控Redis,是使用redis_exporter插件来监控,redis_exporter项目地址:https://github.com/oliver006/redis_exporter
二、安装redis_exporter
下载redis_exporter需要到github.com中下载,可能会比较慢,所以可以用github加速服务下载,具体百度吧。
cd /usr/local/src/
wget https://github.com/oliver006/redis_exporter/releases/download/v1.23.0/redis_exporter-v1.23.0.linux-amd64.tar.gz
tar xzf redis_exporter-v1.23.0.linux-amd64.tar.gz -C /usr/local/prometheus/
ln -s /usr/local/prometheus/redis_exporter-v1.23.0.linux-amd64/redis_exporter /usr/local/prometheus/redis_exporter
四、创建mysqld_exporter的systemctl启动文件并启动
不管用systemctl 还是supervisor管理启动,都需要创建一个prometheus的用户,并且将exporter可执行文件授权prometheus
# 先创建一个prometheus的用户
useradd prometheus -s /sbin/nologin -M
chown -R prometheus.prometheus /usr/local/prometheus
1、使用systemctl形式
# vim /usr/lib/systemd/system/redis_exporter.service
[Unit]
Description=redis_exporter
After=network.target
[Service]
Type=simple
User=prometheus
# 如果redis没有密码,
ExecStart=/usr/local/prometheus/redis_exporter -redis.addr 127.0.0.1:6379 -web.listen-address 0.0.0.0:9121
#如果redis有密码
ExecStart=/usr/local/prometheus/redis_exporter -redis.addr 127.0.0.1:6379 -redis.password 123456 -web.listen-address 0.0.0.0:9121
Restart=on-failure
[Install]
WantedBy=multi-user.target
启动
chown -R root:root /usr/lib/systemd/system/redis_exporter.service
chmod 644 /usr/lib/systemd/system/redis_exporter.service
systemctl daemon-reload
systemctl enable redis_exporter.service
systemctl start redis_exporter.service
2、使用supervisor形式
# vim /etc/supervisor.d/redis_exporter.ini
[program:redis_exporter]
directory=/usr/local/prometheus
command=/usr/local/prometheus/redis_exporter -redis.addr 192.168.0.184:6379 -redis.password 123456 -web.listen-address 0.0.0.0:9121
user=mysql
autostart=true
autorestart=true
startsecs = 2
redirect_stderr=true
stdout_logfile=/var/log/redis_exporter.log
启动
supervisorctl update
supervisorctl start redis_exporter
3、检查是否启动
# ps检查
ps -ef |grep redis_exporter
# netstat/ss 检查
netstat/ss -luntp |grep 9121
五、查看redis_exporter监控到的指标
~]# curl localhost:9121/metrics
# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 0
go_gc_duration_seconds{quantile="0.25"} 0
go_gc_duration_seconds{quantile="0.5"} 0
go_gc_duration_seconds{quantile="0.75"} 0
go_gc_duration_seconds{quantile="1"} 0
go_gc_duration_seconds_sum 0
go_gc_duration_seconds_count 0
####此处省略若干,因为获取到的metrics实在太多,影响阅读,有兴趣自己curl命令查看下完整的。
redis_target_scrape_request_errors_total 0
# HELP redis_up Information about the Redis instance
# TYPE redis_up gauge
redis_up 1
# HELP redis_uptime_in_seconds uptime_in_seconds metric
# TYPE redis_uptime_in_seconds gauge
redis_uptime_in_seconds 1710
六、在prometheus的server端添加msyqld_exporter的相关配置
# vim /usr/local/prometheus/prometheus.yml
scrape_configs:
- job_name: 'redis'
static_configs:
- targets: ['xxx.xxx.xxx.xxx:9121']
7、重新加载prometheus的server端配置
curl -XPOST http://prometheus.xxxxxxxxx.com/-/reload
8、编写告警规则和告警
告警规则模板:https://github.com/oliver006/redis_exporter/blob/v1.23.0/contrib/redis-mixin/alerts/redis.yaml
告警模板:https://github.com/oliver006/redis_exporter/blob/v1.23.0/contrib/redis-mixin/rules/redis.yaml
其中文件,可以自行修改,修改后放于自己服务器上。
9、配置grafana的Dashboard
grafana模板:https://grafana.com/grafana/dashboards/7362
grafana模板:github提供的json文件:https://github.com/oliver006/redis_exporter/blob/v1.23.0/contrib/redis-mixin/dashboards/redis-overview.json
有的地方需要自行修改,请根据需要自行修改,当然也有更多更适合自己的grafana,请自行查找吧。
- 点赞
- 收藏
- 关注作者
评论(0)