redis-expoter监控redis

https://juejin.cn/post/7119751560900378637#heading-3

一. redis配置远程连接

1
2
3
4
5
6
7
8
# 允许任何主机连接、访问
bind 127.0.0.1 改为 bind 0.0.0.0

# 关闭保护模式
protected-mode yes 改为 protected-mode no

# 允许启动后在后台运行,即关闭命令行窗口后仍能运行
daemonize no 改为 daemonize yes

二. 构建redis-expoter

docker run构建

1
2
# cmd构建redis_exporter
docker run -d --name redis_exporter --restart always -p 9121:9121 oliver006/redis_exporter --redis.addr redis://host:6379 --redis.password 'password'

dokcer-compose构建

1
2
3
4
5
6
7
8
9
10
11
12
13
# docker-compose构建redis-expoter
version: "3.0"
services:
redis_exporter:
image: oliver006/redis_exporter
container_name: redis_exporter
hostname: redis_exporter
restart: unless-stopped
ports:
- "9121:9121"
environment:
- REDIS_ADDR=localhost:6379
#- REDIS_PASSWORD=password

prometheus配置

1
2
3
4
- job_name: 'redis_exporter'
scrape_interval: 10s
static_configs:
- targets: ['redis_exporter:9121']

二. 效果

localhost:9121image-20230616112017251

grafana (12328)image-20230616140928840