A teammate wants to leave the Redis MONITOR command running on a production primary to watch traffic; what does that cost, and what do you do instead?
answer
- every command echoed to a client
- formatted on the main thread
- the docs' example lost half
- its output buffer has no cap
- bounded capture or per-command counters
basics
~20 sMONITOR makes the main thread format and send every command to each watcher; the docs' example lost over half its throughput on most tests. A slow reader's output buffer has no default cap. Prefer commandstats, or a short supervised capture.
solid answer
~50 s`MONITOR` turns a connection into a stream of every command the server executes, so while it is attached, the main thread formats each command into a line and queues it for every watcher. The Redis docs show one `MONITOR` client taking `SET` from about 95,000 to 42,000 requests per second, in a run they call unscientific, so treat that as a warning and not a constant. The second risk is memory: a `MONITOR` client is in the `normal` class, whose default `client-output-buffer-limit` is `0 0 0`, so a slow reader grows its buffer without limit. It also exposes values in plain text and omits admin commands. So I refuse to leave it on. For the traffic mix, I diff `INFO commandstats`. For hot keys, I use `HOTKEYS START` on 8.6 or later. If I do need the raw stream, I capture for seconds, supervised, and check that it ended.
code
bash · 2 linestimeout 5 redis-cli MONITOR > /tmp/monitor-sample.txt
redis-cli CLIENT LIST TYPE normal | grep 'flags=O'go deeper
Recall that MONITOR streams every command the server processes, that it is a debugging tool with a real throughput cost, and that you stop it with Ctrl-C in redis-cli.
Explain why the cost arises on the main thread, quote the documented example honestly as an example, and describe what the stream omits: admin commands, rejected commands, durations.
Add the memory failure from a slow reader in the uncapped normal class, the plain-text exposure, how to find a forgotten watcher with flags=O, and the cheaper tool for each real question.
Set a team rule: raw MONITOR on production needs a named owner, a time limit and an agreed place for the capture, and restrict it through ACLs so that it cannot run casually.
## What MONITOR does `MONITOR` is a debugging command. It turns a connection into an endless stream of the commands the server processes, one line each, with a timestamp, the database, the client address and the arguments: ```text 1339518090.420270 [0 127.0.0.1:60866] "set" "x" "6" ``` That is useful for spotting what an application really sends. It is also the most expensive way to find out. ## The three costs **1. Throughput.** After each command runs, Redis builds the line for it and appends it to each watcher's output, all on the main thread that also executes commands. `MONITOR` clients are among those kept on the main thread, so enabling `io-threads` does not take this work away from it. The docs illustrate the cost with what they call a "totally unscientific" benchmark: | Test | Without `MONITOR` | With one `MONITOR` | |---|---|---| | `SET` | 95,419 req/s | 41,823 req/s | | `GET` | 104,275 req/s | 45,330 req/s | | `PING_INLINE` | 101,936 req/s | 58,479 req/s | The documented wording is that "in this particular case", one client can reduce throughput by more than 50%, and more clients reduce it further. It is an example, not a constant: the drop depends on the traffic and the machine. **2. Memory.** Although `MONITOR` connections carry an internal replica flag, Redis classifies them as `normal` clients. The default in `redis.conf` is `client-output-buffer-limit normal 0 0 0`, which means no limit. If the watcher reads slowly, over a slow link or through a slow terminal, the buffer grows. That memory counts towards `used_memory`, and the docs describe what is set aside from eviction accounting as basically replica and AOF buffers, so a stalled `MONITOR` can push a server towards `maxmemory` and trigger evictions. `maxmemory-clients` could evict such a client, but it is off by default. **3. Exposure.** Keys and values appear in plain text. Only `AUTH` and similar secrets are redacted. A capture file of production traffic is therefore a copy of production data, and should be treated as one. ## What it does not show The stream feels complete, and it is not: - **Admin commands** are not logged, for security reasons. Neither is `QUIT`. - **Rejected commands** do not appear. The feed happens in the command execution path, so a command refused for `-NOPERM` or `-OOM` never reaches it. - **Duration and replies** are absent. A line says a command ran, not how long it took or what came back. So it is neither an audit log nor a latency tool. ## What to do instead Match the question to a cheaper tool: | Question | Tool | |---|---| | What is the traffic made of? | Two snapshots of `INFO commandstats`, subtracted | | What is being refused? | `INFO errorstats`, `rejected_calls` | | Which clients are connected, and what did they last run? | `CLIENT LIST` | | Which keys are hottest? | `HOTKEYS START` with a `DURATION`, on Redis 8.6 or later | | Is anything still sending traffic to this node? | A few seconds of `MONITOR` is reasonable | That last row is a legitimate use. The Redis administration guide suggests `MONITOR` for confirming that an old primary is no longer receiving queries before promoting a replica. When you truly need raw commands, keep it small: 1. Get agreement that the instance has headroom now, and do not start during a peak. 2. Run from a nearby host and write to a file instead of a terminal. 3. Limit the time to seconds, not minutes. 4. Watch `omem` for that client in `CLIENT LIST`. 5. Confirm it has gone, and delete the capture when you are done. On a replica, `MONITOR` puts the load on the replica rather than the primary, but it shows only what that replica executes, so reads sent to the primary will be missing. ## Finding a forgotten one The cost exists only while a watcher is attached: with an empty list of monitors, the feed function returns at once. So "leaving it on" means a connection stays open, and it can be found. Look for `flags=O` in `CLIENT LIST`, then close it with `CLIENT KILL ID <id>`. Tools built on `MONITOR` hold such a connection as well, so check for them after any debugging session.
- How do you find and stop a MONITOR that someone forgot about?Run `CLIENT LIST TYPE normal` and look for `flags=O`, because `MONITOR` clients belong to the normal class. Note its `addr` to find out whose it was, check `omem` to see whether a backlog has built up, then close it with `CLIENT KILL ID` and the entry's `id`.
- Does Redis pay any of this cost when nobody is running MONITOR?Almost none. The function that feeds watchers returns immediately when the list of monitors is empty, before any formatting happens. So there is no setting to switch on or off: the cost starts when a client issues `MONITOR` and ends when that connection closes or leaves monitor mode through `RESET`.
- Would you run MONITOR during a redis-benchmark run to see what it sends?Not during a run you intend to keep. The Redis benchmarking guide warns that `MONITOR` significantly affects the measured performance, while calling `INFO` at intervals is probably fine. Inspect the commands on a short separate run, or use the `INFO commandstats` difference from before and after the benchmark.
- MONITOR always costs exactly half of throughput on any server.
- A MONITOR client is a replica, so the replica output buffer limit caps it.
- MONITOR gives a complete audit log of every command, including admin commands.
- Enabling io-threads moves MONITOR's formatting and delivery off the main thread.
- MONITOR redacts values, so its capture files are safe to keep and share.
- MONITOR output shows how long each command took, so it can replace latency tools.
Assumes Redis 8.10; the HOTKEYS command family is available from Redis 8.6, so older servers have no such alternative.