Show live usage: CPU % and Mem % in the table, in-use on the info screen
CI / pytest and ruff (pull_request) Successful in 3m49s
CI / pytest and ruff (push) Has been cancelled

The guest table gets two last columns, CPU % (cpu * 100) and Mem %
(mem / maxmem), each with one decimal. They show "-" for a guest that
is not running or lacks the field.

The info screen's Resources table gets a header and an "In use"
column: CPU %, memory MiB with %, swap for containers, and rootfs used
GiB with % for containers. VM disks show "-", because the API reports
0 without guest-agent disk info. The info screen reads status and
usage in one status/current call (new cli.current).

After an action, the acted guest's status and usage both come from
status/current, so a guest that has just started no longer shows the
lagging listing's 0.0 %.

One blind-written test expected a VM's CPU cell to read "4 cores". VMs
have always shown sockets ("4 cores × 1 socket", as the resources
spec and its tests define), so that expectation was corrected.

Closes #12

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit was merged in pull request #24.
This commit is contained in:
DuckbootandClaude Opus 5.5 committed 2026-11-02 23:52:32 +01:00
1 parent 8c2b48a04c
commit eec65e0585
6 files changed
+356 -12

No files matched your search

+39
View File
@@ -512,3 +512,42 @@ CLI facts (cv4pve-cli 2.4.0, read-only probes):
- [x] Live on CT 104: take `tui_live_test`, listed; roll back (CT running -> started
again); delete; list back to the baseline (no snapshots); CT running.
- [ ] PR with `Closes #8`, merge after user OK.
---
# Live usage: CPU %, memory used, disk used (issue #12)
## Decision (user-approved)
Usage in the main table and in the info screen's Resources section. Values refresh with
the listing (`g`, after actions); no auto-refresh and no rrddata trend (out of scope).
CLI facts (read-only probes):
- `get guests -o json` per guest: `cpu` (fraction of the guest's CPUs, 0..1; the web UI
shows `cpu*100` %), `mem`, `maxmem` (bytes), `disk`, `maxdisk` (bytes). Stopped guests
have 0s. VMs report `disk: 0` (no guest-agent disk info) - shown as `-`, not 0.
- `api get /nodes/<node>/<qemu|lxc>/<vmid>/status/current -o json` -> key/value list:
`status`, `cpu`, `cpus`, `mem`, `maxmem`, `disk`, `maxdisk`, `uptime`; CTs also
`swap`, `maxswap`; VMs also `freemem`, `balloon`.
### `cli.py`
- `current(guest) -> dict` - the status/current key/value list as a dict.
- `status(guest)` keeps its behaviour (returns `current(guest)["status"]`), argv
unchanged.
### `app.py`
- Main table: two new columns at the end, "CPU %" and "Mem %": `cpu*100` and
`mem/maxmem*100`, one decimal; `-` for a guest that is not running or lacks the field.
- Info screen Resources table gets a header and a third column: Resource | Configured |
In use. The load uses `cli.current(guest)` (one call) for both the live status and the
usage. In use, only when running:
- CPU: `<cpu*100:.1f> %`
- Memory: `<mem MiB> MiB (<pct:.0f> %)`
- Swap (CT): `<swap MiB> MiB`
- Disk rootfs (CT): `<disk GiB:.1f> GiB (<pct:.0f> %)`; other disks and all VM disks `-`
- otherwise `-`.
A failure of `cli.current` keeps today's behaviour (inline "unavailable", status
unknown -> not running).