Learn Labs
Operations

Monitoring

INFO, SLOWLOG, LATENCY, client lists, and Redis in Prometheus

Redis tells you almost everything about itself through a handful of commands. redis_exporter turns the same data into Prometheus metrics, so the stack from the Prometheus & Grafana module can graph and alert on it.

INFO

INFO has sections; ask for the one you need:

INFO serverversion, uptime, config file, process idINFO clientsconnected_clients, blocked_clients, maxclientsINFO memoryused_memory, rss, fragmentation, maxmemory, policyINFO persistencerdb/aof status, last save, rewrite in progressINFO statsops/s, hits/misses, evicted_keys, expired_keys, rejected_connections, latest_fork_usecINFO replicationrole, replicas, offsets, link statusINFO commandstatsper command: calls, total usec, usec_per_call, rejected, failedINFO keyspacekeys and keys-with-TTL per databaseINFO errorstatscounts by error type (NOPERM, OOM, WRONGTYPE, ...)

The numbers worth knowing by heart:

SignalWhereWatch for
Memory vs limitused_memory / maxmemoryApproaching 100%
Evictionsevicted_keysAny, on a data store; a rising rate, on a cache
Hit ratiokeyspace_hits / (hits + misses)Dropping on a cache
Clientsconnected_clients, rejected_connectionsNear maxclients; any rejections
Blocked clientsblocked_clientsExpected with BRPOP/XREAD BLOCK; unexpected otherwise
Persistencerdb_last_bgsave_status, aof_last_write_statusAnything but ok
Replicationmaster_link_status, replica lagdown; lag growing
Fork timelatest_fork_usecTens of milliseconds = a latency spike every save

SLOWLOG

The slowlog records commands whose execution exceeded slowlog-log-slower-than (10 ms in this repo). Network and queueing time aren't included: it measures how long the command held the main thread.

SLOWLOG GET 10
1) 1) (integer) 14              # id
 2) (integer) 1791792000      # when
 3) (integer) 182340          # duration in microseconds: 182 ms!
 4) 1) "KEYS"                 # the command and arguments
    2) "*"
 5) "172.18.0.5:51522"        # client
 6) "worker-3"                # client name, if set with CLIENT SETNAME
SLOWLOG LEN
SLOWLOG RESET

Every entry is a moment when all other clients waited. Name your connections (CLIENT SETNAME, or the client_name option in most libraries) so the slowlog tells you which service is responsible.

LATENCY

The latency monitor records events that took longer than latency-monitor-threshold (100 ms here): commands, forks, AOF fsyncs, expiry cycles, eviction cycles.

LATENCY LATESTthe latest and max spike per event typeLATENCY HISTORY forktime series of one eventLATENCY DOCTORa human-readable diagnosis with adviceredis-cli --latencyclient-side: continuous PING round-trip timesredis-cli --latency-history -i 5the same, in 5-second buckets

redis-cli --latency measures what clients actually feel, including the network; SLOWLOG and LATENCY show what the server was doing. A spike in the first without either of the others points at the network, the host (swap, CPU steal), or client-side problems.

CLIENT LIST

CLIENT LIST
id=12 addr=172.18.0.5:51522 name=worker-3 age=310 idle=0 db=0 cmd=xreadgroup
qbuf=0 omem=0 tot-mem=22400 user=app ...

CLIENT KILL ID 12             # disconnect one client
CLIENT NO-EVICT on            # protect an admin connection from client eviction

Look for clients with a large omem (output buffer), which are slow consumers, often Pub/Sub, and for thousands of idle connections from a pool sized too large.

Redis in Prometheus

This repo's redis-exporter (oliver006/redis_exporter) runs INFO and a few other commands on every scrape, as the restricted exporter ACL user. The Prometheus stack scrapes it as job redis:

# from ../prometheus
docker compose -f compose_prod.yaml up -d
open http://localhost:3001     # Grafana -> Databases -> Redis Overview

Queries behind the dashboard:

redis_memory_used_bytes / redis_memory_max_bytes                           # memory vs limit
sum(rate(redis_commands_processed_total[5m]))                              # ops/s
rate(redis_keyspace_hits_total[5m])
/ (rate(redis_keyspace_hits_total[5m]) + rate(redis_keyspace_misses_total[5m]))  # hit ratio
topk(8, sum by (cmd) (rate(redis_commands_total[5m])))                     # busiest commands
sum by (cmd) (rate(redis_commands_duration_seconds_total[5m]))
/ sum by (cmd) (rate(redis_commands_total[5m]))                          # avg server time per command
rate(redis_evicted_keys_total[5m])
redis_master_link_up                                                       # on replicas

And the alerts in prometheus/config/rules/alerts.yml: RedisDown, RedisMemoryNearLimit, RedisEvictingKeys, RedisReplicationBroken, and RedisPersistenceFailing.

Lab

  1. Start the Prometheus stack and open the Redis Overview dashboard.
  2. Run leaderboard.py and redis-benchmark and watch ops/s and commands by type move.
  3. Run KEYS * as default a few times on a seeded instance, then SLOWLOG GET 5. (On this small dataset it may be under 10 ms. Lower the threshold with CONFIG SET slowlog-log-slower-than 0 to log everything, then set it back to 10000.)
  4. Stop a replica in the ha profile and watch RedisReplicationBroken go pending, then firing.

On this page