Skip to content

compose: add stats command - #5310

Open
cvas22 wants to merge 2 commits into
containerd:mainfrom
cvas22:feat/compose-stats
Open

cvas22 wants to merge 2 commits into
containerd:mainfrom
cvas22:feat/compose-stats

Conversation

@cvas22

@cvas22 cvas22 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

I added nerdctl compose stats, one of the Compose commands still listed as unimplemented in the command reference (tracked in #3867).

It follows docker compose stats:

  • nerdctl compose stats [SERVICE...] shows the live resource usage of the project's containers, or only those of the given services.
  • -a/--all, --format, --no-stream and --no-trunc work as in nerdctl stats.
  • By default only running containers are shown; --all includes stopped ones.

The command collects the project's container IDs and hands them to the existing container.Stats, the same way compose top reuses container.Top, so the output and formats are identical to nerdctl stats. When the project has no matching containers it returns right away, because container.Stats with no IDs would show every container on the host.

Changes:

  • cmd/nerdctl/compose/compose_stats.go: the command
  • cmd/nerdctl/compose/compose_stats_linux_test.go: tests for all services, one service, and a stopped service skipped by default
  • docs/command-reference.md: documented the command and removed it from the unimplemented list

Notes

I ran TestComposeStats locally as root in a privileged container, with containerd and buildkitd from the out-full build and nerdctl built from this branch:

--- PASS: TestComposeStats (29.40s)
    --- PASS: TestComposeStats/all_services (1.05s)
    --- PASS: TestComposeStats/one_service (1.05s)
    --- PASS: TestComposeStats/stopped_service_is_skipped (10.24s)

golangci-lint (the version pinned in the Makefile) reports 0 issues for ./cmd/nerdctl/compose/, for both Linux and Windows. I haven't tried rootless mode.

I also had a subtest for --all with a stopped service. It passed locally, where containerd v2 runs rootful, but in CI it timed out after 3 minutes on the containerd v1.7.36 and rootless jobs (stats --all --no-stream ... svc1 never returned). compose stats passes the container IDs to the same container.Stats that nerdctl stats uses, and nothing tests nerdctl stats --no-stream on a stopped container, so I suspect the same hang with nerdctl stats --no-stream <stopped container> on those setups. I haven't confirmed that. I removed that subtest from this PR instead of guessing at a fix in container.Stats, and I'm happy to look into it separately if you'd like.

@cvas22

cvas22 commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

The failing jobs aren't failing in TestComposeStats. build failed downloading a module from the Go proxy (INTERNAL_ERROR on google.golang.org/grpc). The almalinux-8 jobs fail in unrelated tests (TestRunContainerWithStaticIP6, TestVolumeRemove, TestWait), and kubernetes in TestKubeCommitSave. I don't have permission to re-run the jobs, so could a maintainer re-run the failed ones?

@cvas22
cvas22 force-pushed the feat/compose-stats branch from d842d72 to 0ac74e5 Compare November 4, 2026 02:13
Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>
@cvas22
cvas22 force-pushed the feat/compose-stats branch from 0ac74e5 to 6e5c375 Compare November 4, 2026 07:52
compose stats held the global compose lock until it exited. Without
--no-stream it runs until interrupted, so it blocked every other compose
command in the meantime. Release the lock before streaming, as compose
logs does (containerd#3678).

Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>
@cvas22
cvas22 force-pushed the feat/compose-stats branch from 89d0132 to 4ee788c Compare November 5, 2026 17:41
@cvas22

cvas22 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Same fix as in #5325: compose stats now releases the global compose lock before streaming (4ee788c), like compose logs does since #3678. Without --no-stream it runs until interrupted, so holding the lock blocked every other compose command in the meantime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants