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:
The numbers worth knowing by heart:
| Signal | Where | Watch for |
|---|---|---|
| Memory vs limit | used_memory / maxmemory | Approaching 100% |
| Evictions | evicted_keys | Any, on a data store; a rising rate, on a cache |
| Hit ratio | keyspace_hits / (hits + misses) | Dropping on a cache |
| Clients | connected_clients, rejected_connections | Near maxclients; any rejections |
| Blocked clients | blocked_clients | Expected with BRPOP/XREAD BLOCK; unexpected otherwise |
| Persistence | rdb_last_bgsave_status, aof_last_write_status | Anything but ok |
| Replication | master_link_status, replica lag | down; lag growing |
| Fork time | latest_fork_usec | Tens 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 RESETEvery 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.
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 evictionLook 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 OverviewQueries 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 replicasAnd the alerts in prometheus/config/rules/alerts.yml:
RedisDown, RedisMemoryNearLimit, RedisEvictingKeys,
RedisReplicationBroken, and RedisPersistenceFailing.
redis_exporter's per-key metrics (--check-keys, --check-single-keys)
are tempting for "graph the length of my queue." They run commands per
key on every scrape. Point them at a handful of specific keys, never a
wildcard over the keyspace, or the exporter becomes the slowest client
your Redis has.
Lab
- Start the Prometheus stack and open the Redis Overview dashboard.
- Run
leaderboard.pyandredis-benchmarkand watch ops/s and commands by type move. - Run
KEYS *asdefaulta few times on a seeded instance, thenSLOWLOG GET 5. (On this small dataset it may be under 10 ms. Lower the threshold withCONFIG SET slowlog-log-slower-than 0to log everything, then set it back to 10000.) - Stop a replica in the
haprofile and watchRedisReplicationBrokengo pending, then firing.