Configure comprehensive Redis monitoring using Prometheus Redis Exporter and Grafana dashboards. Monitor Redis performance metrics, memory usage, connections, and replication status with automated alerts for production environments.
Prerequisites
- Redis server installed and running
- Prometheus server installed
- Grafana installed and configured
- Basic understanding of systemd services
What this solves
Redis monitoring is essential for production deployments to track performance, memory usage, connection patterns, and prevent outages. This tutorial sets up comprehensive Redis monitoring using Prometheus Redis Exporter to collect metrics and Grafana dashboards for visualization and alerting, supporting single instances, clusters, and Sentinel deployments.
Step-by-step installation
Update system packages
Start by updating your package manager to ensure you get the latest versions of all components.
sudo apt update && sudo apt upgrade -y
Install required packages
Install wget, tar, and other utilities needed for downloading and installing the Redis exporter.
sudo apt install -y wget tar curl systemd
Create Redis exporter user
Create a dedicated system user for running the Redis exporter service securely.
sudo useradd --system --no-create-home --shell /bin/false redis_exporter
Download and install Redis exporter
Download the latest Redis exporter binary and install it to the system binary directory.
cd /tmp
wget https://github.com/oliver006/redis_exporter/releases/download/v1.58.0/redis_exporter-v1.58.0.linux-amd64.tar.gz
tar -xzf redis_exporter-v1.58.0.linux-amd64.tar.gz
sudo mv redis_exporter-v1.58.0.linux-amd64/redis_exporter /usr/local/bin/
sudo chown redis_exporter:redis_exporter /usr/local/bin/redis_exporter
sudo chmod 755 /usr/local/bin/redis_exporter
Create Redis exporter configuration
Create a configuration directory and environment file for the Redis exporter with connection settings.
sudo mkdir -p /etc/redis_exporter
sudo chown redis_exporter:redis_exporter /etc/redis_exporter
sudo chmod 755 /etc/redis_exporter
REDIS_ADDR=redis://localhost:6379
REDIS_EXPORTER_LOG_FORMAT=txt
REDIS_EXPORTER_DEBUG=false
REDIS_EXPORTER_CHECK_KEYS=*
REDIS_EXPORTER_INCLUDE_SYSTEM_METRICS=true
sudo chown redis_exporter:redis_exporter /etc/redis_exporter/redis_exporter.env
sudo chmod 640 /etc/redis_exporter/redis_exporter.env
Create systemd service file
Create a systemd service file to manage the Redis exporter as a system service with proper security restrictions.
[Unit]
Description=Redis Exporter
Documentation=https://github.com/oliver006/redis_exporter
After=network.target
Wants=network.target
[Service]
Type=simple
User=redis_exporter
Group=redis_exporter
EnvironmentFile=/etc/redis_exporter/redis_exporter.env
ExecStart=/usr/local/bin/redis_exporter
SyslogIdentifier=redis_exporter
Restart=always
RestartSec=5
Security settings
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=true
ProtectControlGroups=true
ProtectKernelModules=true
ProtectKernelTunables=true
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
RestrictNamespaces=true
RestrictRealtime=true
DevicePolicy=closed
MemoryDenyWriteExecute=true
PrivateDevices=true
PrivateTmp=true
SystemCallFilter=@system-service
SystemCallErrorNumber=EPERM
[Install]
WantedBy=multi-user.target
Configure Redis exporter for authenticated Redis
If your Redis instance requires authentication, update the configuration with password and advanced options.
REDIS_ADDR=redis://localhost:6379
REDIS_PASSWORD=your_redis_password
REDIS_EXPORTER_LOG_FORMAT=txt
REDIS_EXPORTER_DEBUG=false
REDIS_EXPORTER_CHECK_KEYS=user:,session:,cache:*
REDIS_EXPORTER_INCLUDE_SYSTEM_METRICS=true
REDIS_EXPORTER_EXPORT_CLIENT_LIST=true
REDIS_EXPORTER_SKIP_TLS_VERIFICATION=false
Start and enable Redis exporter
Enable and start the Redis exporter service to begin collecting metrics on system boot.
sudo systemctl daemon-reload
sudo systemctl enable redis_exporter
sudo systemctl start redis_exporter
sudo systemctl status redis_exporter
Configure Prometheus scrape config
Add the Redis exporter as a scrape target in your Prometheus configuration file.
global:
scrape_interval: 15s
evaluation_interval: 15s
rule_files:
- "/etc/prometheus/rules/*.yml"
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'redis'
static_configs:
- targets: ['localhost:9121']
scrape_interval: 10s
metrics_path: /metrics
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: localhost:9121
Configure Prometheus service discovery for multiple Redis instances
Set up file-based service discovery to automatically monitor multiple Redis instances.
sudo mkdir -p /etc/prometheus/file_sd
sudo chown prometheus:prometheus /etc/prometheus/file_sd
sudo chmod 755 /etc/prometheus/file_sd
- targets:
- 'localhost:9121'
labels:
service: 'redis'
environment: 'production'
instance_type: 'primary'
datacenter: 'dc1'
- targets:
- '203.0.113.10:9121'
labels:
service: 'redis'
environment: 'production'
instance_type: 'replica'
datacenter: 'dc1'
- targets:
- '203.0.113.11:9121'
labels:
service: 'redis'
environment: 'production'
instance_type: 'replica'
datacenter: 'dc2'
Update Prometheus configuration for service discovery
Modify Prometheus configuration to use file-based service discovery for Redis monitoring.
- job_name: 'redis-cluster'
file_sd_configs:
- files:
- '/etc/prometheus/file_sd/redis_targets.yml'
refresh_interval: 30s
scrape_interval: 10s
metrics_path: /metrics
relabel_configs:
- source_labels: [__address__]
target_label: redis_instance
- target_label: __tmp_prometheus_job_name
replacement: redis
Create Redis monitoring rules
Set up Prometheus alerting rules for Redis monitoring to detect performance issues and outages.
sudo mkdir -p /etc/prometheus/rules
sudo chown prometheus:prometheus /etc/prometheus/rules
sudo chmod 755 /etc/prometheus/rules
groups:
- name: redis.rules
rules:
- alert: RedisDown
expr: redis_up == 0
for: 5m
labels:
severity: critical
annotations:
summary: "Redis instance is down"
description: "Redis instance {{ $labels.instance }} has been down for more than 5 minutes"
- alert: RedisMemoryUsageHigh
expr: (redis_memory_used_bytes / redis_memory_max_bytes) * 100 > 90
for: 5m
labels:
severity: warning
annotations:
summary: "Redis memory usage is high"
description: "Redis instance {{ $labels.instance }} memory usage is {{ $value }}%"
- alert: RedisConnectionsHigh
expr: redis_connected_clients > 1000
for: 5m
labels:
severity: warning
annotations:
summary: "Redis connection count is high"
description: "Redis instance {{ $labels.instance }} has {{ $value }} connections"
- alert: RedisSlowQueries
expr: redis_slowlog_length > 10
for: 2m
labels:
severity: warning
annotations:
summary: "Redis has slow queries"
description: "Redis instance {{ $labels.instance }} has {{ $value }} slow queries in log"
- alert: RedisReplicationLag
expr: redis_slave_lag_in_seconds > 30
for: 5m
labels:
severity: critical
annotations:
summary: "Redis replication lag is high"
description: "Redis slave {{ $labels.instance }} is lagging {{ $value }} seconds behind master"
Configure Redis Cluster monitoring
Set up monitoring for Redis Cluster deployments with cluster-specific metrics and exporters.
REDIS_ADDR=redis://203.0.113.10:7000
REDIS_PASSWORD=cluster_password
REDIS_EXPORTER_IS_CLUSTER=true
REDIS_EXPORTER_CHECK_SINGLE_KEYS=false
REDIS_EXPORTER_CHECK_STREAMS=true
REDIS_EXPORTER_PING_ON_CONNECT=true
REDIS_EXPORTER_INCL_SYSTEM_METRICS=true
[Unit]
Description=Redis Cluster Exporter
After=network.target
[Service]
Type=simple
User=redis_exporter
Group=redis_exporter
EnvironmentFile=/etc/redis_exporter/cluster_exporter.env
ExecStart=/usr/local/bin/redis_exporter --web.listen-address=:9122
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
Configure Redis Sentinel monitoring
Set up dedicated monitoring for Redis Sentinel deployments to track failover and master election events.
REDIS_ADDR=redis://203.0.113.20:26379
REDIS_EXPORTER_IS_SENTINEL=true
REDIS_EXPORTER_CHECK_SINGLE_KEYS=false
REDIS_EXPORTER_SENTINEL_MASTERS=mymaster,secondary
REDIS_EXPORTER_LOG_FORMAT=json
[Unit]
Description=Redis Sentinel Exporter
After=network.target
[Service]
Type=simple
User=redis_exporter
Group=redis_exporter
EnvironmentFile=/etc/redis_exporter/sentinel_exporter.env
ExecStart=/usr/local/bin/redis_exporter --web.listen-address=:9123
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
Restart Prometheus
Restart Prometheus to load the new configuration and begin scraping Redis metrics.
sudo systemctl restart prometheus
sudo systemctl status prometheus
Import Grafana Redis dashboard
Import a pre-built Redis dashboard into Grafana for comprehensive monitoring visualization.
curl -X POST \
http://admin:admin@localhost:3000/api/dashboards/import \
-H 'Content-Type: application/json' \
-d '{
"dashboard": {
"id": 763,
"title": "Redis Dashboard for Prometheus Redis Exporter",
"tags": ["redis", "prometheus"]
},
"overwrite": true,
"inputs": [{
"name": "DS_PROMETHEUS",
"type": "datasource",
"pluginId": "prometheus",
"value": "Prometheus"
}]
}'
Configure Grafana alerting
Set up Grafana alerts for Redis monitoring with notification channels for critical issues.
curl -X POST \
http://admin:admin@localhost:3000/api/alert-notifications \
-H 'Content-Type: application/json' \
-d '{
"name": "redis-alerts",
"type": "email",
"settings": {
"addresses": "admin@example.com",
"subject": "Redis Alert: {{ range .Alerts }}{{ .Annotations.summary }}{{ end }}"
}
}'
Configure Redis monitoring for specific use cases
Monitor Redis with SSL/TLS encryption
Configure Redis exporter to monitor Redis instances with SSL/TLS encryption enabled.
REDIS_ADDR=rediss://redis.example.com:6380
REDIS_PASSWORD=secure_password
REDIS_EXPORTER_TLS_CLIENT_KEY_FILE=/etc/ssl/private/redis-client.key
REDIS_EXPORTER_TLS_CLIENT_CERT_FILE=/etc/ssl/certs/redis-client.crt
REDIS_EXPORTER_TLS_CA_CERT_FILE=/etc/ssl/certs/ca.crt
REDIS_EXPORTER_SKIP_TLS_VERIFICATION=false
Set up custom Redis metrics collection
Configure custom key patterns and Lua scripts for application-specific Redis monitoring.
REDIS_EXPORTER_CHECK_KEYS=user:,session:active:,cache:hot:*
REDIS_EXPORTER_CHECK_SINGLE_KEYS=stats:total_users,config:feature_flags
REDIS_EXPORTER_SCRIPT_PATH=/etc/redis_exporter/scripts/custom_metrics.lua
REDIS_EXPORTER_LUA_SCRIPT_TIMEOUT=60s
-- Custom Redis metrics collection script
local active_sessions = redis.call('SCARD', 'active_sessions')
local queue_length = redis.call('LLEN', 'job_queue')
local cache_hits = redis.call('GET', 'cache_hits') or 0
local cache_misses = redis.call('GET', 'cache_misses') or 0
return {
active_sessions = active_sessions,
queue_length = queue_length,
cache_hit_ratio = tonumber(cache_hits) / (tonumber(cache_hits) + tonumber(cache_misses))
}
Verify your setup
Confirm that Redis monitoring is working correctly by checking the exporter metrics and Prometheus targets.
# Check Redis exporter status
sudo systemctl status redis_exporter
Verify metrics endpoint
curl http://localhost:9121/metrics | grep redis_up
Check Prometheus targets
curl http://localhost:9090/api/v1/targets | jq '.data.activeTargets[] | select(.job=="redis")'
Test Redis connectivity through exporter
curl -s http://localhost:9121/metrics | grep "redis_connected_clients"
Verify Grafana dashboard
curl -s http://admin:admin@localhost:3000/api/dashboards/uid/redis | jq '.dashboard.title'
Common issues
| Symptom | Cause | Fix |
|---|---|---|
| Redis exporter shows "connection refused" | Redis not running or wrong address | Check Redis status: sudo systemctl status redis and verify REDIS_ADDR |
| Authentication errors in exporter logs | Wrong or missing Redis password | Update REDIS_PASSWORD in /etc/redis_exporter/redis_exporter.env |
| Prometheus not scraping Redis metrics | Firewall blocking port 9121 | Open port: sudo ufw allow 9121 or check iptables rules |
| Missing cluster metrics | REDIS_EXPORTER_IS_CLUSTER not set | Set REDIS_EXPORTER_IS_CLUSTER=true for cluster deployments |
| High memory usage by exporter | Too many keys being checked | Limit CHECK_KEYS to specific patterns, not wildcards |
| Grafana dashboard shows no data | Wrong Prometheus datasource | Verify datasource URL and test connection in Grafana settings |
Next steps
- Configure Prometheus long-term storage with Thanos for unlimited data retention
- Configure Redis Sentinel with SSL/TLS encryption and authentication for high availability
- Setup centralized log aggregation with Elasticsearch 8, Logstash 8, and Kibana 8 (ELK Stack)
- Implement Nginx Redis cluster caching for high availability
- Configure Redis Cluster monitoring with custom Grafana dashboards
Automated install script
Run this to automate the entire setup
#!/usr/bin/env bash
set -euo pipefail
# Redis Monitoring Setup with Prometheus and Grafana
# Production-ready installation script
# Color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Variables
REDIS_EXPORTER_VERSION="1.58.0"
REDIS_ADDR="${1:-redis://localhost:6379}"
REDIS_PASSWORD="${2:-}"
# Usage
usage() {
echo "Usage: $0 [redis_addr] [redis_password]"
echo " redis_addr: Redis connection string (default: redis://localhost:6379)"
echo " redis_password: Redis password (optional)"
echo "Example: $0 redis://localhost:6379 mypassword"
exit 1
}
# Helper functions
log() { echo -e "${GREEN}[INFO]${NC} $1"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
error() { echo -e "${RED}[ERROR]${NC} $1" >&2; }
step() { echo -e "${BLUE}[$1]${NC} $2"; }
# Cleanup function
cleanup() {
if [ $? -ne 0 ]; then
error "Installation failed. Cleaning up..."
systemctl stop redis_exporter 2>/dev/null || true
systemctl disable redis_exporter 2>/dev/null || true
rm -f /etc/systemd/system/redis_exporter.service
rm -rf /etc/redis_exporter
rm -f /usr/local/bin/redis_exporter
userdel redis_exporter 2>/dev/null || true
systemctl daemon-reload
fi
}
trap cleanup ERR
# Check prerequisites
check_prereqs() {
if [[ $EUID -ne 0 ]]; then
error "This script must be run as root or with sudo"
exit 1
fi
# Auto-detect distribution
if [ -f /etc/os-release ]; then
. /etc/os-release
case "$ID" in
ubuntu|debian)
PKG_MGR="apt"
PKG_INSTALL="apt install -y"
PKG_UPDATE="apt update && apt upgrade -y"
;;
almalinux|rocky|centos|rhel|ol|fedora)
PKG_MGR="dnf"
PKG_INSTALL="dnf install -y"
PKG_UPDATE="dnf update -y"
;;
amzn)
PKG_MGR="yum"
PKG_INSTALL="yum install -y"
PKG_UPDATE="yum update -y"
;;
*)
error "Unsupported distribution: $ID"
exit 1
;;
esac
else
error "Cannot detect distribution. /etc/os-release not found."
exit 1
fi
log "Detected distribution: $PRETTY_NAME"
log "Package manager: $PKG_MGR"
}
# Validate arguments
if [ "$#" -gt 2 ]; then
usage
fi
check_prereqs
step "1/8" "Updating system packages"
$PKG_UPDATE
step "2/8" "Installing required packages"
$PKG_INSTALL wget tar curl systemd
step "3/8" "Creating Redis exporter user"
if ! id redis_exporter &>/dev/null; then
useradd --system --no-create-home --shell /bin/false redis_exporter
log "Created redis_exporter user"
else
warn "User redis_exporter already exists"
fi
step "4/8" "Downloading and installing Redis exporter"
cd /tmp
if [ ! -f "redis_exporter-v${REDIS_EXPORTER_VERSION}.linux-amd64.tar.gz" ]; then
wget -q "https://github.com/oliver006/redis_exporter/releases/download/v${REDIS_EXPORTER_VERSION}/redis_exporter-v${REDIS_EXPORTER_VERSION}.linux-amd64.tar.gz"
fi
tar -xzf "redis_exporter-v${REDIS_EXPORTER_VERSION}.linux-amd64.tar.gz"
mv "redis_exporter-v${REDIS_EXPORTER_VERSION}.linux-amd64/redis_exporter" /usr/local/bin/
chown redis_exporter:redis_exporter /usr/local/bin/redis_exporter
chmod 755 /usr/local/bin/redis_exporter
rm -rf "redis_exporter-v${REDIS_EXPORTER_VERSION}.linux-amd64"* /tmp/redis_exporter*
log "Redis exporter installed to /usr/local/bin/redis_exporter"
step "5/8" "Creating Redis exporter configuration"
mkdir -p /etc/redis_exporter
chown redis_exporter:redis_exporter /etc/redis_exporter
chmod 755 /etc/redis_exporter
# Create environment file
cat > /etc/redis_exporter/redis_exporter.env << EOF
REDIS_ADDR=${REDIS_ADDR}
$([ -n "$REDIS_PASSWORD" ] && echo "REDIS_PASSWORD=${REDIS_PASSWORD}")
REDIS_EXPORTER_LOG_FORMAT=txt
REDIS_EXPORTER_DEBUG=false
REDIS_EXPORTER_CHECK_KEYS=*
REDIS_EXPORTER_INCLUDE_SYSTEM_METRICS=true
REDIS_EXPORTER_EXPORT_CLIENT_LIST=true
REDIS_EXPORTER_SKIP_TLS_VERIFICATION=false
EOF
chown redis_exporter:redis_exporter /etc/redis_exporter/redis_exporter.env
chmod 640 /etc/redis_exporter/redis_exporter.env
log "Configuration created at /etc/redis_exporter/redis_exporter.env"
step "6/8" "Creating systemd service file"
cat > /etc/systemd/system/redis_exporter.service << 'EOF'
[Unit]
Description=Redis Exporter
Documentation=https://github.com/oliver006/redis_exporter
After=network.target
Wants=network.target
[Service]
Type=simple
User=redis_exporter
Group=redis_exporter
EnvironmentFile=/etc/redis_exporter/redis_exporter.env
ExecStart=/usr/local/bin/redis_exporter
SyslogIdentifier=redis_exporter
Restart=always
RestartSec=5
# Security settings
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=true
ProtectControlGroups=true
ProtectKernelModules=true
ProtectKernelTunables=true
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
RestrictNamespaces=true
RestrictRealtime=true
DevicePolicy=closed
MemoryDenyWriteExecute=true
PrivateDevices=true
PrivateTmp=true
SystemCallFilter=@system-service
SystemCallErrorNumber=EPERM
[Install]
WantedBy=multi-user.target
EOF
chmod 644 /etc/systemd/system/redis_exporter.service
log "Systemd service file created"
step "7/8" "Starting and enabling Redis exporter"
systemctl daemon-reload
systemctl enable redis_exporter
systemctl start redis_exporter
# Wait a moment for service to start
sleep 2
step "8/8" "Verifying installation"
if systemctl is-active --quiet redis_exporter; then
log "Redis exporter service is running"
# Test metrics endpoint
if curl -sf http://localhost:9121/metrics > /dev/null; then
log "Metrics endpoint is accessible at http://localhost:9121/metrics"
else
warn "Metrics endpoint test failed, but service is running"
fi
# Show service status
echo
log "Service status:"
systemctl status redis_exporter --no-pager
echo
log "Installation completed successfully!"
echo
echo -e "${GREEN}Next steps:${NC}"
echo "1. Configure Prometheus to scrape http://localhost:9121/metrics"
echo "2. Import Redis Grafana dashboard (ID: 763 or 11835)"
echo "3. Set up alerting rules for critical Redis metrics"
echo
echo -e "${BLUE}Configuration files:${NC}"
echo "- Service: /etc/systemd/system/redis_exporter.service"
echo "- Config: /etc/redis_exporter/redis_exporter.env"
echo "- Binary: /usr/local/bin/redis_exporter"
echo
echo -e "${BLUE}Useful commands:${NC}"
echo "- Check status: systemctl status redis_exporter"
echo "- View logs: journalctl -u redis_exporter -f"
echo "- Test metrics: curl http://localhost:9121/metrics"
else
error "Redis exporter service failed to start"
echo "Check logs with: journalctl -u redis_exporter -n 20"
exit 1
fi
Review the script before running. Execute with: bash install.sh