In Redis, what do INFO commandstats and INFO errorstats report, and how do you read calls, usec, rejected_calls and failed_calls correctly?
answer
- one line per command, one per error
- counted since start or last reset
- before execution versus during execution
- time inside the command only
- errors grouped by reply prefix
basics
~20 sCommandstats gives each command's calls, time and rejected and failed counts; errorstats counts error replies by prefix. Both are cumulative, so subtract two snapshots. Rejected commands never ran; failed ones ran and are also in calls.
solid answer
~40 s`INFO commandstats` prints one `cmdstat_<command>` line per command that has been used, with `calls`, `usec`, `usec_per_call`, `rejected_calls` and `failed_calls`. `calls` counts executions. `rejected_calls` counts refusals before execution, such as `-NOPERM` or `-OOM`, and those are not in `calls`. `failed_calls` counts errors raised during execution, such as `WRONGTYPE`, and those are in `calls`. `usec` covers only time inside the command, so a healthy `usec_per_call` does not rule out queueing or network delay. `INFO errorstats` counts every error reply by its prefix, as `errorstat_OOM:count=12`. Both are cumulative since startup or the last `CONFIG RESETSTAT`, so I take two snapshots and subtract instead of resetting, which would zero the counters for every other reader too. Neither section tells me which key or which client was involved.
code
bash · 4 linesredis-cli INFO commandstats > /tmp/cmd.before
sleep 300
redis-cli INFO commandstats > /tmp/cmd.after
diff /tmp/cmd.before /tmp/cmd.aftergo deeper
Recall that commandstats reports per-command counts and time, errorstats counts errors by type, and that you must name commandstats to see it.
Explain the difference between rejected and failed and how each relates to calls, why usec excludes waiting, and why you subtract two snapshots rather than read one.
Use the deltas to find the command with a small share of calls and a large share of time, and to read an OOM or NOPERM pattern. Know that resetting statistics damages every other reader.
Decide that per-command deltas are collected continuously, so nobody needs a reset during an incident. Treat the resulting command mix as a shared artifact that capacity work starts from.
## What the two sections are **`commandstats`** breaks the server's work down by command. **`errorstats`** breaks its error replies down by type. Together they answer the first questions about an unfamiliar instance: what is this traffic made of, what takes the time, and what is being refused. `commandstats` is not in plain `INFO`, so you ask for it by name. `errorstats` is in the default set. A `commandstats` line looks like this, and a command gets a line only once one of its counters is non-zero: ```text cmdstat_get:calls=21,usec=175,usec_per_call=8.33,rejected_calls=0,failed_calls=0 ``` Subcommands appear under their full name, joined with a `|`, such as `cmdstat_client|list`. From Redis 8.8, a command that has been written to the slow log also shows `slowlog_count`, `slowlog_time_ms_sum` and `slowlog_time_ms_max`. ## What each field means | Field | Meaning | Includes | |---|---|---| | `calls` | Times the command reached execution | Failed calls, but not rejected ones | | `usec` | Total time spent executing | Only time inside the command | | `usec_per_call` | `usec` divided by `calls` | A mean, which hides outliers | | `rejected_calls` | Refused before execution | Not part of `calls` | | `failed_calls` | An error raised during execution | Also counted in `calls` | The split between the last two tells you where to look: - **Rejected** means the server refused without running the command: `-NOPERM` from an ACL, `-OOM` at the memory limit, `READONLY` on a replica, or the wrong number of arguments. - **Failed** means the command ran and returned an error, such as `WRONGTYPE` from a `GET` on a list. The docs call `usec` CPU time. In the source, it is elapsed time measured around the command's handler on the main thread. Either way, it excludes the time a command spent waiting to be read, and the time its reply spent going out. So a low `usec_per_call` paired with a slow caller means the delay is somewhere else. Because it is a mean, one enormous call can hide among millions of small ones; `INFO latencystats` gives per-command percentiles from the same execution time, with p50, p99 and p99.9 by default. ## Turning counters into answers Every field is **cumulative** since the server started or since the last `CONFIG RESETSTAT`. A single reading is a lifetime average, which may describe last month's traffic. To describe now: 1. Take a snapshot of `INFO commandstats`. 2. Wait a known interval, such as five minutes. 3. Take another snapshot and subtract, command by command. From those differences you get the **command mix** from `calls`, and the **share of execution time** from `usec`. A command with 1% of the calls and 60% of the `usec` is where to look first. That same mix is the honest input to a later capacity question, because it tells you which commands a benchmark should exercise. Resist `CONFIG RESETSTAT` as a shortcut. It also zeroes `total_commands_processed`, the keyspace hit and miss counters and the error tables, so every dashboard and colleague reading those counters sees a false drop. It does not reset `uptime_in_seconds`, so anyone dividing a counter by uptime afterwards gets a wrong rate. ## Reading errorstats `errorstats` groups replies by **prefix**, the first word after the `-` up to the first space: ```text errorstat_ERR:count=4 errorstat_OOM:count=12 errorstat_WRONGTYPE:count=3 ``` Some things worth knowing: - It covers both rejected and failed commands, and `total_error_replies` in `stats` is the overall count. - A mistyped command never resolves to a command at all, so it adds to `errorstat_ERR` but to no `cmdstat_` line. - Redis keeps a limited table of prefixes. When it would exceed 128 distinct ones, for example because scripts invent their own error codes, Redis logs a warning, clears the table, and shows a single `errorstat_ERRORSTATS_DISABLED`. `CONFIG RESETSTAT` turns it back on. A useful reading combines the two sections. If `errorstat_OOM` climbs and `SET`'s `rejected_calls` climbs with it, writes are being refused at the door. If `errorstat_WRONGTYPE` climbs alongside `failed_calls` on `GET`, an application is treating a key as the wrong type, which often follows a deploy. ## Limits These sections are per node and per command. They do not say which key or which client caused a number. `errorstat_NOPERM` rising tells you an ACL is refusing somebody, and `CLIENT LIST` or the ACL log is the next step for finding out who.
- Why can a mistyped command appear in errorstats but not in commandstats?An unknown command is refused before Redis has resolved it to any command, so there is no `cmdstat_` line whose `rejected_calls` could grow. The error reply is still counted, under `errorstat_ERR` and in `total_error_replies`. A wrong argument count differs, because the command is known, so its `rejected_calls` does rise.
- SET shows a rising rejected_calls and errorstat_OOM is climbing. What does that combination tell you?Writes are being refused before they run because the server is at its memory limit and could not free enough room. `calls` for `SET` stops counting those attempts, so write traffic can look like it fell while callers are actually getting errors. The cause is then a memory question.
- rejected_calls are included in calls, so calls is the total number of attempts.
- A failed call never reached execution, so it is not in calls.
- usec_per_call is the latency that callers experience for that command.
- A single commandstats reading shows what the traffic looks like right now.
- Run CONFIG RESETSTAT whenever you want a clean measurement; it harms nothing.
- Commandstats can tell you which key is hot and which client is sending it.
Assumes Redis 8.10; the slowlog_count, slowlog_time_ms_sum and slowlog_time_ms_max fields on commandstats lines appear from Redis 8.8.