一、下载安装
1、下载
https://github.com/oliver006/redis_exporter/releases/tag/v1.44.0
2、安装配置
1、安装redis_exporter
tar -zxvf redis_exporter-v1.44.0.linux-amd64.tar.gz
cp -r redis_exporter-v1.6.1.linux-amd64 /usr/local/redis_exporter
2、开启redis_exporter服务,监控单实例
cd /usr/local/redis_exporter
./redis_exporter -web.listen-address 192.168.10.131:9121 -redis.addr 192.168.10.132:6379 \
-redis.password 123456 &>redis_exporter.log &
3、prometheus配置
- job_name: redis_exporter
scrape_interval: 10s
static_configs:
- targets: ['192.168.10.131:9121']
4、添加redis_exporter为系统服务开机启动配置文件redis_exporter.service
vi /usr/lib/systemd/system/redis_exporter.service
[Unit]
Description=Prometheus Redis daemon
After=network.target
[Service]
Type=simple
Restart=always
ExecStart=/usr/local/redis_exporter/redis_exporter \
-redis.addr localhost:6379 \
-redis.password 123456
[Install]
WantedBy=multi-user.target
二、配置采集多个redis主机
./redis_exporter -web.listen-address 192.168.10.131:9121 -redis.addr 192.168.10.132:6379 \
-redis.password 123456 &>redis_exporter.log &
启动不用变,如果不设置-redis.addr它默认去找localhost:6379
配置更改:
- job_name: 'GT_WORK_REDIS_CULSTER'
static_configs:
- targets:
- redis://192.168.10.132:8807
- redis://192.168.10.132:8808
- redis://192.168.10.132:8807
- redis://192.168.10.132:8808
- redis://192.168.10.132:8807
- redis://192.168.10.132:8808
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.10.131:9121
- job_name: 'gtcq-gt-work-redis_exporter'
static_configs:
- targets:
- 192.168.10.131:9121
附录:以json方式
Redis 实例被列在 targets 下面,Redis Exporter 主机名是通过最后的 relabel_config 规则配置的。标签:__,exporter,target,redis,192.168,Prometheus,targets From: https://blog.51cto.com/u_13236892/5890043
如果 Redis 实例需要认证,那么你可以通过 --redis.password 参数指定 Redis Exporter 访问 Redis 的密码。
如果是这样的话,多个 Redis 实例之鞥呢使用多个 Redis Exporter 来进行监控。
也可以使用一个 JSON file 通过 文件发现来配置多个实例,
scrape_configs:
- job_name: 'redis_exporter_targets'
file_sd_configs:
- files:
- targets-redis-instances.json
metrics_path: /scrape
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: <<REDIS-EXPORTER-HOSTNAME>>:9121
## config for scraping the exporter itself
- job_name: 'redis_exporter'
static_configs:
- targets:
- <<REDIS-EXPORTER-HOSTNAME>>:9121
这个 targets-redis-instances.json 内容如下进行排列
[
{
"targets": [ "redis://redis-host-01:6379", "redis://redis-host-02:6379"],
"labels": { }
}
]
Prometheus 使用文件监视,所有对 json 文件的更改都会使 Prometheus 立即生效。