Add container machine stats command#1920
Open
nico81 wants to merge 1 commit into
Open
Conversation
A running container machine is backed by a container, so its resource usage is already available through the existing container stats path. Expose it with a new `container machine stats [<id>]` subcommand. - Extract the sampling, CPU%/byte formatting, table rendering, and streaming loop out of the private internals of `container stats` into a shared StatsRendering helper, parametrized by the id-column header, and refactor ContainerStats onto it with no behavior change. - Add MachineStats, mirroring `machine inspect` for target resolution and reusing StatsRendering. It resolves the machine's backing container id, supports table/json/yaml/toml and live streaming with --no-stream, and labels output with the machine id. - Add unit tests for the formatting/CPU helpers (previously untested) and an integration test for the new command. - Document the command in command-reference.md and container-machine.md.
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of Change
Motivation and Context
container statsshows live CPU / memory / network / block-I/O / process stats for containers, but there is no equivalent for container machines —container machineonly 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 runcontainer stats <that-id>.This adds
container machine stats [<id>] [--no-stream] [--format table|json|yaml|toml], the machine counterpart tocontainer stats. Resolves #1919.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 callcontainer machine runalready uses on the backing container — with no new collection logic and no new API route. The shared sampling / CPU% / byte formatting / table rendering / streaming is extracted out of the private internals ofcontainer statsinto aStatsRenderinghelper reused by both commands (no behavior change tocontainer stats); output rows are labeled by machine id.Testing
swift buildclean andswift test --filter StatsRenderinggreen — new unit tests cover the CPU% / byte-format helpers (previously untested), plus an integration test for the new command. Manually verified against a running machine:container machine stats <name>(table / json / yaml) matchescontainer stats <backing-id>, and stopped / nonexistent machines produce clear errors. Docs updated:command-reference.mdandcontainer-machine.md.