Fix misleading memory usage for VMs without guest-side stats

Windows VMs only report balloon current/max/rss, not available/unused.
Previously this fell through to RSS which showed ~100% usage.
Now VMs without balloon.available show allocated RAM without a usage bar.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-24 22:07:17 -06:00
parent 695f4ef6dc
commit 1c51d03350

7
app.py
View File

@@ -216,13 +216,12 @@ def get_vm_live_stats():
balloon_unused = s.get("balloon_unused", 0) balloon_unused = s.get("balloon_unused", 0)
balloon_rss = s.get("balloon_rss", 0) balloon_rss = s.get("balloon_rss", 0)
if balloon_avail > 0: if balloon_avail > 0 and balloon_unused >= 0:
mem_total = balloon_avail // 1024 # KiB to MB mem_total = balloon_avail // 1024 # KiB to MB
mem_used = (balloon_avail - balloon_unused) // 1024 mem_used = (balloon_avail - balloon_unused) // 1024
elif balloon_rss > 0:
mem_total = 0
mem_used = balloon_rss // 1024
else: else:
# No guest-side stats (e.g. Windows without full guest agent).
# Mark as unavailable — frontend will show allocated RAM only.
mem_total = 0 mem_total = 0
mem_used = 0 mem_used = 0