feat: live container stats on rows, a Stats tab and per-project totals #22

Merged
jfro merged 1 commit from feat/11-container-stats into main 2026-11-30 16:59:59 +00:00
Owner

Live resource usage for running containers, read from the engine's stats stream (bollard stats, stream: true).

What's in it

  • Rows: CPU % and memory on each running container's row; compose project rows show the sum of their containers. Hover for network rates.
  • Stats tab in the detail pane (Info · Stats · Logs): CPU, memory (with its limit), network ↓/↑ and disk read/write, each with a small graph of the last three minutes. Byte totals since start sit under each figure.
  • Per-project roll-up: a project's Stats tab shows its totals plus a row per running service (click one to jump to it).
  • Only while visible: streams run only for running containers, and only while the window is shown (not minimized) on the Containers page. Switching to Volumes/Images, hiding or minimizing the window stops them; history is sent only for the selection.
  • Figures follow docker stats: CPU = container CPU time / host CPU time × online CPUs (100% = one core), memory = usage minus inactive_file (cgroup v2) or total_inactive_file (v1). Rates come from counter deltas and drop to 0 when counters reset (restart). A stream that ends is retried every 2 s while the container is still wanted.
  • Mock data: each running fixture container has its own usage profile with gently varying figures, and history is pre-filled so screenshots show full graphs. New stats screenshot scene; README features and screenshots updated.

Left out: totals in the tray tooltip (optional in the issue). It would mean streaming stats for every container while the window is closed, which works against "only while visible"; happy to add it as a follow-up if wanted.

Code: src/stats.rs (parsing, history, session), ContainerModel.watchStats(ids, detailIds) + stats_json property, StatsView.qml, StatGraph.qml (Canvas sparkline).

Tested

  • cargo fmt --check, clippy --all-targets -D warnings with and without mock, cargo build, cargo test (5 new tests: docker-stats math on a cgroup v2 frame, v1 names, first frame without CPU, rates/restart, history cap), all with Rust 1.100.0.
  • Against a real Docker 29.10.1 engine (dind): figures match docker stats --no-stream (busy-loop container ~90–99% CPU, postgres ~31 MB vs 30.15 MiB); stopped containers show "Not Running"; switching to Volumes closes the stat streams (socket count drops by one per running container).

Screenshots (mock data)

Stats tab for a compose project (dark):
stats

Light:
stats-light

Figures on the container rows:
containers

Closes #11

Live resource usage for running containers, read from the engine's stats stream (bollard `stats`, `stream: true`). **What's in it** - **Rows:** CPU % and memory on each running container's row; compose project rows show the sum of their containers. Hover for network rates. - **Stats tab** in the detail pane (Info · Stats · Logs): CPU, memory (with its limit), network ↓/↑ and disk read/write, each with a small graph of the last three minutes. Byte totals since start sit under each figure. - **Per-project roll-up:** a project's Stats tab shows its totals plus a row per running service (click one to jump to it). - **Only while visible:** streams run only for running containers, and only while the window is shown (not minimized) on the Containers page. Switching to Volumes/Images, hiding or minimizing the window stops them; history is sent only for the selection. - Figures follow `docker stats`: CPU = container CPU time / host CPU time × online CPUs (100% = one core), memory = usage minus `inactive_file` (cgroup v2) or `total_inactive_file` (v1). Rates come from counter deltas and drop to 0 when counters reset (restart). A stream that ends is retried every 2 s while the container is still wanted. - **Mock data:** each running fixture container has its own usage profile with gently varying figures, and history is pre-filled so screenshots show full graphs. New `stats` screenshot scene; README features and screenshots updated. **Left out:** totals in the tray tooltip (optional in the issue). It would mean streaming stats for every container while the window is closed, which works against "only while visible"; happy to add it as a follow-up if wanted. **Code:** `src/stats.rs` (parsing, history, session), `ContainerModel.watchStats(ids, detailIds)` + `stats_json` property, `StatsView.qml`, `StatGraph.qml` (Canvas sparkline). **Tested** - `cargo fmt --check`, `clippy --all-targets -D warnings` with and without `mock`, `cargo build`, `cargo test` (5 new tests: docker-stats math on a cgroup v2 frame, v1 names, first frame without CPU, rates/restart, history cap), all with Rust 1.100.0. - Against a real Docker 29.10.1 engine (dind): figures match `docker stats --no-stream` (busy-loop container ~90–99% CPU, postgres ~31 MB vs 30.15 MiB); stopped containers show "Not Running"; switching to Volumes closes the stat streams (socket count drops by one per running container). **Screenshots** (mock data) Stats tab for a compose project (dark): ![stats](https://git.knope.dev/attachments/66e997c0-a746-4f94-bccb-65b239577a1f) Light: ![stats-light](https://git.knope.dev/attachments/4b1ce293-9e7f-4db1-b2b1-19109e5664b4) Figures on the container rows: ![containers](https://git.knope.dev/attachments/4b60a655-2ac8-48d4-bfa6-fe568aee4289) Closes #11
feat: live container stats on rows, a Stats tab and per-project totals
All checks were successful
CI / test (pull_request) Successful in 4m39s
CI / test (push) Successful in 4m49s
253c22f167
Streams the engine's stats for running containers while the Containers page is on screen: CPU and memory on each row (summed for compose projects), and a Stats tab with CPU, memory, network and disk graphs of the last three minutes plus a per-service breakdown for projects. Mock data gets example stats and the README a Stats screenshot.

Closes #11
jfro left a comment

Review from Nye (posted on its behalf):

Review: PR #22 (container stats), 253c22f — Approve, no blocking findings

CI gates (Rust 1.100.0): fmt --check, clippy --all-targets -D warnings (with and without mock), cargo test (10 pass), build --features mock: all pass.

Real engine (Docker 26.1.5, cgroup v2):

  • Rows match docker stats --no-stream: busy loop 99–100% vs 99.24%; 1.9 MB vs 1.824 MiB; 4.2 MB vs 4 MiB; 434 kB vs 424 KiB. Compose row sums its services (6.1 MB = 1.9 + 4.2). Stats tab network and disk totals match NetIO/BlockIO (13 kB rx; 3.0 MB read / 67 MB written).
  • Streams only while shown, counted by Krane's unix sockets: 13 with 3 running → Volumes page 10 → back 13; minimized 10. Stopping a container drops one, starting adds it back, and restart stays at 13. Nothing leaks.
  • Load: 33 running containers → 33 streams, Krane at about 1.4% CPU idle, 240 MB RSS.
  • --mock --show: rows and the shop Stats tab (graphs plus per-service rows) render like the screenshots. README and build.rs are updated.

Non-blocking notes:

  1. follow() opens a fresh Docker::connect_with_local_defaults() per container. That's fine on a unix socket, but when #16 lands it must use the shared selected-engine client. Over ssh:// each client starts its own ssh master, so 33 containers would mean 33 ssh processes. Please carry this into #16.
  2. Podman (5.4) sends a stats frame every 5 s, not every 1 s. So the 180-point history covers about 15 min there, and row figures update every 5 s. The math still works: I checked a Podman frame and got 98.8% against podman stats' 97.9%. The UI copy only says "few minutes", so this is cosmetic. Maybe cap history by time instead of point count later.
  3. Cosmetic: after a stream reconnects (a restart), the first frame has no CPU, so Entry::push updates latest but keeps the old point. For one tick the totals are new and the rates are old.
  4. Tray totals left out: agreed, it fits "only while visible".
Review from Nye (posted on its behalf): ## Review: PR #22 (container stats), 253c22f — Approve, no blocking findings **CI gates (Rust 1.100.0):** fmt --check, clippy --all-targets -D warnings (with and without `mock`), cargo test (10 pass), build --features mock: all pass. **Real engine (Docker 26.1.5, cgroup v2):** - Rows match `docker stats --no-stream`: busy loop 99–100% vs 99.24%; 1.9 MB vs 1.824 MiB; 4.2 MB vs 4 MiB; 434 kB vs 424 KiB. Compose row sums its services (6.1 MB = 1.9 + 4.2). Stats tab network and disk totals match NetIO/BlockIO (13 kB rx; 3.0 MB read / 67 MB written). - Streams only while shown, counted by Krane's unix sockets: 13 with 3 running → Volumes page 10 → back 13; minimized 10. Stopping a container drops one, starting adds it back, and restart stays at 13. Nothing leaks. - Load: 33 running containers → 33 streams, Krane at about 1.4% CPU idle, 240 MB RSS. - `--mock --show`: rows and the shop Stats tab (graphs plus per-service rows) render like the screenshots. README and build.rs are updated. **Non-blocking notes:** 1. `follow()` opens a fresh `Docker::connect_with_local_defaults()` per container. That's fine on a unix socket, but when #16 lands it must use the shared selected-engine client. Over ssh:// each client starts its own ssh master, so 33 containers would mean 33 ssh processes. Please carry this into #16. 2. Podman (5.4) sends a stats frame every 5 s, not every 1 s. So the 180-point history covers about 15 min there, and row figures update every 5 s. The math still works: I checked a Podman frame and got 98.8% against podman stats' 97.9%. The UI copy only says "few minutes", so this is cosmetic. Maybe cap history by time instead of point count later. 3. Cosmetic: after a stream reconnects (a restart), the first frame has no CPU, so `Entry::push` updates `latest` but keeps the old `point`. For one tick the totals are new and the rates are old. 4. Tray totals left out: agreed, it fits "only while visible".
jfro merged commit 253c22f167 into main 2026-11-30 16:59:59 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
jfro/krane!22
No description provided.