Prometheus监控redis

2023-12-31 10:48:04

Redis 服务 启用

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

Redis_exporter

  • docker直接运行
    ?
docker run -d --name redis_exporter -p 9121:9121 \
oliver006/redis_exporter \
--redis.addr redis://10.19.1.220:6379 \
--redis.password '123456'
  • docker-compose.yml
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

prometheus/prometheus.yml 配置

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常用的监控指标

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"
```

redis触发器

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=)

dashboard

Redis: https://grafana.com/grafana/dashboards/11835

文章来源:https://blog.csdn.net/zuopiezia/article/details/135313229
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。