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