cat >docker-compose.yml<<'EOF'
version: '3'
services:
? redis:
? ? image: redis:5
? ? container_name: redis
? ? command: redis-server --requirepass 123456 --maxmemory 512mb
? ? restart: always
? ? volumes:
? ? ? - /data/redis/data:/data
? ? ports:
? ? ? - 6379:6379
docker run -d --name redis_exporter -p 9121:9121 \
oliver006/redis_exporter \
--redis.addr redis://10.19.1.220:6379 \
--redis.password '123456'
cd /data/redis/
```
cat >docker-compose.yaml << 'EOF'
version: '3.3'
services:
? redis_exporter:
? ? image: oliver006/redis_exporter
? ? container_name: redis_exporter
? ? restart: always
? ? environment:
? ? ? REDIS_ADDR: "10.19.1.220:6379"
? ? ? REDIS_PASSWORD: 123456
? ? ports:
? ? ? - '9121:9121'
EOF
cat >> prometheus/prometheus.yml << 'EOF'
? - job_name: 'redis_exporter'
? ? scrape_interval: 30s
? ? static_configs:
? ? - targets: ['10.19.1.220:9121']
? ? ? labels:
? ? ? ? instance: redis服务器?
EOF
加载配置文件
curl -X POST http://localhost:9090/-/reload
redis_uptime_in_seconds
rate(redis_cpu_sys_seconds_total[1m])+rate(redis_cpu_user_seconds_total[1m])
redis_memory_used_bytes
redis_memory_max_bytes
delta(redis_net_input_bytes_total[1m])
delta(redis_net_putput_bytes_total[1m])
redis_connected_clients
redis_rejected_connections_total
redis_connected_clients / redis_config_maxclients * 100
prometheus配置
mkdir /prometheus
```
vi prometheus/prometheus.yml
#报警(触发器)配置
rule_files:
? - "alert.yml"
? - "rules/*.yml"
```
cat > prometheus/rules/redis.yml << 'EOF'
groups:
- name: redis
? rules:
? - alert: RedisDown
? ? expr: redis_up == 0
? ? for: 0m
? ? labels:
? ? ? severity: critical
? ? annotations:
? ? ? summary: 'Redis Down,实例: {{ $labels.instance }}'
? ? ? description: "Redis实例 is down"
? - alert: RedisMissingBackup
? ? expr: time() - redis_rdb_last_save_timestamp_seconds > 60 * 60 * 24
? ? for: 0m
? ? labels:
? ? ? severity: critical
? ? annotations:
? ? ? summary: 'Redis 备份丢失,实例: {{ $labels.instance }}'
? ? ? description: "Redis 24 小时未备份"
? - alert: RedisOutOfConfiguredMaxmemory
? ? expr: redis_memory_used_bytes / redis_memory_max_bytes * 100 > 90
? ? for: 2m
? ? labels:
? ? ? severity: warning
? ? annotations:
? ? ? summary: 'Redis Down,实例: {{ $labels.instance }}'
? ? ? description: "Redis实例 is down"
EOF
docker exec -it prometheus promtool check config /etc/prometheus/prometheus.yml
?curl -X POST http://localhost:9090/-/reload
检查
http://10.19.1.206:9090/rules
http://10.19.1.206:9090/alerts?search=)
Redis: https://grafana.com/grafana/dashboards/11835