Deploying Redis Exporter with Docker‑Compose and Configuring Prometheus Monitoring and Alerts
This tutorial demonstrates how to use Docker‑Compose to deploy a Redis exporter, configure Prometheus to collect its metrics, and define alerting rules for Redis health monitoring, providing step‑by‑step commands and YAML examples for a complete monitoring setup.
This guide explains how to deploy the redis_exporter service using Docker‑Compose, then configure Prometheus to scrape its metrics and create alert rules for Redis monitoring.
Docker‑Compose file (docker-compose.yaml) :
version: '3.3'
services:
redis_exporter:
image: oliver006/redis_exporter
container_name: redis_exporter
restart: always
environment:
REDIS_ADDR: "192.168.18.69:6379"
REDIS_PASSWORD: 123456
ports:
- "9121:9121"
EOFCreate the file with cat >docker-compose.yaml <<EOF and start the container in detached mode: docker-compose up -d Prometheus configuration (prometheus.yml) to scrape the exporter:
- job_name: 'redis_exporter'
static_configs:
- targets: ['192.168.18.69:9121']
labels:
instance: test服务器
EOFReload the Prometheus configuration: curl -X POST http://localhost:9090/-/reload Redis alert rules (prometheus/rules/redis.yml) :
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超出配置的最⼤内存,实例:{{ $labels.instance }}"
description: "Redis内存使⽤超过配置最⼤内存的90%"
- alert: RedisRejectedConnections
expr: increase(redis_rejected_connections_total[1m]) > 0
for: 0m
labels:
severity: critical
annotations:
summary: "Redis有拒绝连接,实例:{{ $labels.instance }}"
description: "与Redis 的某些连接被拒绝{{ $value }}"
EOFVerify the Prometheus configuration:
docker exec -it prometheus promtool check config /etc/prometheus/prometheus.ymlThe article ends with a reminder to like, share, and follow for more content.
Practical DevOps Architecture
Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
