container icon indicating copy to clipboard operation
container copied to clipboard

[Request]: container machine stats to show machine resource usage

Open nico81 opened this issue 4 months ago • 1 comments

Feature or enhancement request details

container stats shows live CPU / memory / network / block-I/O / process stats for containers, but there is no equivalent for container machines — container machine only covers lifecycle (create, run, ls, inspect, set, set-default, logs, stop, rm). When running a machine as a persistent Linux environment there is no first-class way to see its resource usage; today you would have to discover the machine's internal backing-container id and run container stats <that-id>.

Proposed: add container machine stats [<id>] [--no-stream] [--format table|json|yaml|toml], the machine counterpart to container stats:

  • Resolves the target machine like container machine inspect (positional id, default machine if omitted).
  • A running machine is already backed by a container (MachineSnapshot.containerId), so the data comes straight from the existing path (ContainerClient().stats(id:)) — the same call container machine run already uses on the backing container — so no new collection logic and no new API route.
  • Output labeled by machine id; same streaming / --no-stream / format options as container stats.

Example:

$ container machine stats my-machine
Machine ID  Cpu %  Memory Usage           Net Rx/Tx            Block I/O            Pids
my-machine  0.42%  512.00 MiB / 2.00 GiB  1.20 KiB / 0.80 KiB  4.00 MiB / 0.00 KiB  7

I've opened a PR implementing this: #1920 — it extracts the shared sampling / CPU% / rendering out of container stats into a helper reused by both commands, with unit + integration tests and docs.

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

nico81 avatar Jul 08 '26 10:07 nico81

Following up on this. I opened #1920 with a working implementation — it reuses the existing container-stats path (no new API route), the refactor to container stats is behavior-preserving, and it includes unit + integration tests and docs. It still applies cleanly to main.

Is machine-level stats something the project wants? Happy to reshape it, or to close the PR if it's not a direction you want to take — just looking for a quick signal so I know whether to keep it current.

nico81 avatar Sep 15 '26 21:09 nico81