Back to lessons

Hosting Operations

Snapshot Container CPU and Memory

You need a quick CPU and memory snapshot for running containers.

Command

docker stats --no-stream --format 'table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}\t{{.BlockIO}}'

What changed

Nothing changes. Docker reads current resource counters.

Danger

safe

When to use it

Use when a host is slow, memory pressure is suspected, or one container may be noisy.

When not to use it

Do not treat one snapshot as a trend; repeat it or use monitoring for longer windows.

Undo or recovery

No undo needed because this command is read-only.

Expected output

A table showing container CPU percentage, memory usage, network I/O, and block I/O.

demo script

Disposable terminal steps

  1. docker stats --no-stream --format 'table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}\t{{.BlockIO}}'
  2. docker stats --no-stream web

simulated output

What it looks like

disposable vessel
::fixture-ready::
$ docker stats --no-stream --format 'table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}\t{{.BlockIO}}'
NAME    CPU %     MEM USAGE / LIMIT     NET I/O        BLOCK I/O
web     0.12%     42.1MiB / 512MiB      1.2MB / 880kB  4.1MB / 0B
api     8.40%     180.4MiB / 512MiB     3.8MB / 1.1MB  18MB / 2MB
::exit-code::0
$ docker stats --no-stream web
CONTAINER ID   NAME  CPU %  MEM USAGE / LIMIT
abc123         web   0.12%  42.1MiB / 512MiB
::exit-code::0

YouTube Short

Docker stats once.

Docker stats defaults to a live stream. Add no-stream for a clean one-time snapshot.

LinkedIn hook

Get Docker resource usage once, without leaving a live dashboard running.

Question: Do you prefer one-shot resource snapshots or live terminal dashboards during incidents?

experiments

A/B tests to run

Metric: save_rate

A: Get Docker resource usage once.

B: Stop leaving docker stats running during triage.