Prometheus 监控Redis需要用到redis_exporter客户端, Prometheus -> redis_exporter这个模式, 类似监控Mysql 一个思路.
1 ) 设置系统代理,golang有可能被墙,导致编译失败.
# Enable the go modules feature
export GO111MODULE=on
# Set the GOPROXY environment variable
export GOPROXY=https://goproxy.io
source /etc/profile
2 )部署 redis_exporter:
# 2.1 )redis_exporter Github 地址:
https://github.com/oliver006/redis_exporter/
# 2.2 ) 开始安装:
cd /data/soft/
git clone https://github.com/oliver006/redis_exporter.git
cd redis_exporter
go build .
./redis_exporter --version
# 2.3 )验证安装结果:
[root@prod-8 redis_exporter]# ./redis_exporter -version
INFO[0000] Redis Metrics Exporter <<< filled in by build >>> build date: <<< filled in by build >>> sha1: <<< filled in by build >>> Go: go1.15.5 GOOS: linux GOARCH: amd64
*** 这样就算是安装完成了.
3 ) 配置 redis_exporter:
# 3.1 ) 带参数启动redis_expoeter:
nohup ./redis_exporter -redis.addr 10.0.2.10:6379 -redis.password 123456 &
# 3.2 ) 参数说明:
-redis.addr # redis的服务地址.
-redis.password # redis认证密码如果没有密码,该参数不需要.
......
*** 还有很多其他的参数可以添加,这两个参数就够用.
# 3.3 ) 访问redis 页面:
curl http://10.0.2.8:9121/Metrics
# 3.3 ) 多个redis 添加
nohup ./redis_exporter -redis.addr 10.0.2.11:6379,10.0.2.11:6380,10.0.2.11:6381 -redis.password 12312312
# 3.4 ) 多实例部署:
......后续再补
4 ) Prometheus.conf 配置:
# 4.1 ) Grafana 添加模板:
模板号: 763 | 4074 均可:
# 4.2 ) Prometheus 添加配置:
vim proemtheus.yml
......
- job_name: 'redis_exporter'
static_configs:
- targets: ['10.0.2.8:9121'] # 注意IP地址和端口
labels:
operator: 'Azure'
area: "中国北部2"
env: 'prod'
......保存退出.
*** 注意给对应主机打标签,可以做报警分组抑制.
# 4.3 ) 重载prometheus配置:
systemctl restart prometheus
systemctl status prometheus
5 ) 访问Prometheus Url 查看截图:
6 ) redis-exporter 启动脚本:
# 6.1 ) 启动脚本内容:
vim /etc/systemd/system/redis_exporter.service
[Unit]
Description=redis_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=work
ExecStart=/data/soft/redis_exporter/redis_exporter -redis.addr=IP:6379 -redis.password=passwd # 注意要更改这里
Restart=on-failure
[Install]
WantedBy=multi-user.target
# 6.2 ) 添加脚本到服务:
systemctl daemon-reload
systemctl enable redis_exporter
systemctl start redis_exporter
systemctl status redis_exporter
# 6.3 ) 命令检测:
6.3.1 ) ps -ef | grep redis-exporter
6.3.2 ) lsof -i:9121