Skip to content

Rank VMs by allocated storage, and unbreak the VM metrics - #663

Open
traviswu-bigstack wants to merge 1 commit into
developfrom
travis.wu/vm-storage-usage-rank
Open

traviswu-bigstack wants to merge 1 commit into
developfrom
travis.wu/vm-storage-usage-rank

Conversation

@traviswu-bigstack

@traviswu-bigstack traviswu-bigstack commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

What type of PR is this?

/kind feature
/kind bug


Which issue(s) this PR fixes?

Part of bigstack-oss/cubecos#1449 (collector: bigstack-oss/cubecos#1450, spec: bigstack-oss/cube-cos-openapi#115).


What this PR does?

Feature — adds storageUsage to the VM metric types: per-VM disk usage as a percentage, ranked high to low, backing the "Disk Usage" option on the VM ranking panel. Same units as the cpuUsage and memoryUsage options it sits beside on that card.

The figure is the guest filesystem reading — used over total across the instance's mounted filesystems — not blocks allocated in the pool. The two diverge by large factors, and the block number is the wrong one to call usage: Ceph keeps a block allocated once written unless the guest passes TRIM through. On a measured instance here the pool reported 85% while the guest reported 14.8%, and an fstrim that freed 32.1 GiB inside the guest moved the pool figure by nothing.

An instance whose qemu-guest-agent does not answer therefore has no reading and does not appear in the ranking, rather than ranking as zero — absent means not measured.

Named storageUsage rather than diskUsage because diskUsage is already the host filesystem percentage.

Bug — all VM metrics were reading a dead database. Six statements still queried Bucket("monasca"). #1457 retired monasca and moved those series to telegraf, so every VM rank and every VM history — cpu, memory, read/write iops, network in/out — returned empty. The VM Ranking card was blank for all of them, not just the new metric. I confirmed all six measurements are actively written in telegraf (80–290 points per 10 min) before switching the bucket.

Bug — ranked values all rendered as 0. Byte counters come back from influx as int64; the float64 type assertion silently yielded 0. Both the rank and history parsers now go through one reader that accepts either.

Bug — selecting the new metric crashed the dashboard with TypeError: Cannot read properties of null (reading 'map'). The rank points now always carry a history slice, never nil.

Bug — isMetricTypeValid is a second hardcoded allowlist beside the OpenAPI enum, so a type missing from it is rejected with 400 no matter what the spec says.


Test results (optional)

1). API docs updated — enum in the submodule (bigstack-oss/cube-cos-openapi#115); api/docs.json is gitignored and generated at build time.

go vet ./internal/... and go build ./cmd clean.

Verified against a live single-node cluster. Before, every VM rank type answered with an empty list; after:

cpuUsage      rows=8   appfw-worker-kmzt9-b4948=39.4
memoryUsage   rows=8   amphora-743f30b5...=39.2
storageUsage  rows=7   lrubuntu=14.7988   (percentage; 1 instance has no guest agent and is absent)
diskReadIops / diskWriteIops / networkTrafficIn / networkTrafficOut   rows=10

storageUsage values match what the guest reports (df inside lrubuntu: 5.7 G of 38 G = 15%), rank points carry a populated history, and the ranking card renders percentages beside the CPU card's % where it previously threw.

Adds storageUsage to the VM metric types: per-VM disk usage as a percentage,
ranked high to low, backing the "Disk Usage" option on the VM ranking panel.
A percentage, in the same units as the cpuUsage and memoryUsage options it
sits beside on that card.

The figure is the guest filesystem reading -- used over total across the
instance's mounted filesystems -- not blocks allocated in the pool. The two
diverge by large factors and the block number is the wrong one to call usage:
Ceph keeps a block allocated once written unless the guest passes TRIM
through, so on one measured instance the pool reported 85% while the guest
reported 14.8%, and an fstrim that freed 32.1 GiB inside the guest moved the
pool figure by nothing.

An instance whose qemu-guest-agent does not answer therefore has no reading
and does not appear in the ranking, rather than ranking as zero. Absent means
not measured.

Named storageUsage rather than diskUsage because diskUsage is already taken
by the host filesystem percentage -- a different entity.

Fixes the six VM statements that still read from the monasca bucket. #1457
retired monasca and moved those series to telegraf, so every VM rank and
every VM history -- cpu, memory, read/write iops, network in/out -- returned
empty against a database nothing writes to any more. The VM Ranking card on
the dashboard was blank for all of them, not only for the new metric. All six
measurements were confirmed to be receiving writes in telegraf before the
switch.

Byte counters come back from influx as int64, not float64. The float64 type
assertion silently yielded 0, so ranked values rendered as zero; the history
parser would have dropped every point. Both now go through one reader that
accepts either.

The rank points always carry a history slice, never nil. The dashboard maps
over it directly, so a nil crashed the page with "Cannot read properties of
null (reading 'map')" the moment the new metric was selected.

isMetricTypeValid is a second, hardcoded allowlist beside the OpenAPI enum;
a type absent from it is rejected with 400 however well the spec describes
it. Submodule bumped for the enum (cube-cos-openapi#115).

Signed-off-by: Travis Wu <travis.wu@bigstack.co>
@traviswu-bigstack
traviswu-bigstack force-pushed the travis.wu/vm-storage-usage-rank branch from c6fc668 to a27e64b Compare September 16, 2026 06:19
@traviswu-bigstack
traviswu-bigstack marked this pull request as ready for review September 16, 2026 06:23
@traviswu-bigstack
traviswu-bigstack requested review from a team and raven-pan as code owners September 16, 2026 06:23
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.

1 participant