prometheus 监控 redis 需要用到 redis_exporter。
cd /usr/local/src
wget https://github.com/oliver006/redis_exporter/releases/download/v0.21.2/redis_exporter-v0.21.2.linux-amd64.tar.gz
mkdir /usr/local/redis_exporter
tar xf redis_exporter-v0.21.2.linux-amd64.tar.gz -C /usr/local/redis_exporter/
# redis_exporter -h
-redis.addr:指明一个或多个 Redis 节点的地址,多个节点使用逗号分隔,默认为 redis://localhost:6379
-redis.password:验证 Redis 时使用的密码;
-redis.file:包含一个或多个redis 节点的文件路径,每行一个节点,此选项与 -redis.addr 互斥。
-web.listen-address:监听的地址和端口,默认为 0.0.0.0:9121
## 无密码
./redis_exporter redis//192.168.111.11:6379 &
## 有密码
redis_exporter -redis.addr 192.168.111.11:6379 -redis.password 123456
$ vim /usr/lib/systemd/system/redis_exporter.service
[Unit]
Description=redis_exporter
Documentation=https://github.com/oliver006/redis_exporter
After=network.target
[Service]
Type=simple
# User=prometheus
ExecStart=/usr/local/redis_exporter/redis_exporter -redis.addr 192.168.111.11:6379 -redis.password 123456
Restart=on-failure
[Install]
WantedBy=multi-user.target
groupadd prometheus useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
```bash
systemctl daemon-reload
systemctl start redis_exporter
systemctl status redis_exporter
ss -tnl|grep 9121
docker run -d --name redis_exporter -p 9121:9121 oliver006/redis_exporter --redis.addr redis://192.168.111.11:6379 --redis.password '123456'
- job_name: "redis-sit"
static_configs:
- targets: ['192.168.111.11:9121']
- job_name: 'redis_exporter_targets'
static_configs:
- targets:
- redis://192.168.111.11:7000
- redis://192.168.111.11:7001
- redis://192.168.111.12:7002
- redis://192.168.111.12:7003
- redis://192.168.111.13:7004
- redis://192.168.111.13:7005
metrics_path: /scrape
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 192.168.111.11:9121