Skip to content

Conversation

@dcantah
Copy link
Member

@dcantah dcantah commented Nov 5, 2025

Closes #824

This implements statistics gathering across the various components, but ultimately this is for implementing a new CLI command: container stats. This shows memory usage, cpu usage, network and block i/o and the number of processes in the container. The new command can inspect stats for 1-N containers and by default continuously updates in a top like stream.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Testing

  • Tested locally
  • Added/updated tests
  • Added/updated docs

This implements statistics gathering across the various components, but
ultimately this is for implementing a new CLI command: `container stats`.
This shows memory usage, cpu usage, network and block i/o and the number
of processes in the container. The new command can inspect stats for 1-N
containers and by default continuously updates in a `top` like stream.
memoryUsageBytes: stats.memory.usageBytes,
memoryLimitBytes: stats.memory.limitBytes,
cpuUsageUsec: stats.cpu.usageUsec,
networkRxBytes: stats.networks.reduce(0) { $0 + $1.receivedBytes },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be more useful to only reduce these at the command line and make all of these fields arrays? If we did can the caller correlate the entries readily with the config?

@Option(name: .long, help: "Format of the output")
var format: ListFormat = .table

@Flag(name: .long, help: "Disable streaming stats and only pull the first result")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about a stream argument that's an enumeration of follow and top (which might not be 100% sensical now but becomes more so if we add arg-based or interactive sort).

public init() {}

public func run() async throws {
if format == .json || noStream {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

json + top doesn't make sense, but json + follow would give you JSONL/NDJSON output.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Request]: "container stats" to show container usage statistics

2 participants