Set up Redis monitoring with Prometheus and Grafana dashboards

Intermediate 45 min Apr 07, 2026 95 views
Ubuntu 24.04 Debian 12 AlmaLinux 9 Rocky Linux 9

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
sudo dnf update -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
sudo dnf 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

Automated install script

Run this to automate the entire setup

Need help?

Don't want to manage this yourself?

We handle managed devops services for businesses that depend on uptime. From initial setup to ongoing operations.