fix: show dash instead of 0% for VMs without guest agent disk data

addresses #367 - when VMs don't have working guest agent data, display a dash instead of misleading 0% disk usage
This commit is contained in:
Pulse Monitor
2025-08-28 12:44:46 +00:00
parent 4f1f77e0ae
commit 84dd6392e5
2 changed files with 15 additions and 1 deletions
@@ -69,6 +69,8 @@ export function GuestRow(props: GuestRowProps) {
});
const diskPercent = createMemo(() => {
if (!props.guest.disk || props.guest.disk.total === 0) return 0;
// Check if usage is -1 (unknown/no guest agent)
if (props.guest.disk.usage === -1) return -1;
return (props.guest.disk.used / props.guest.disk.total) * 100;
});
@@ -185,7 +187,7 @@ export function GuestRow(props: GuestRowProps) {
{/* Disk */}
<td class="p-1 px-2 w-[140px]">
<Show
when={props.guest.disk && props.guest.disk.total > 0}
when={props.guest.disk && props.guest.disk.total > 0 && diskPercent() !== -1}
fallback={<span class="text-gray-400 text-sm">-</span>}
>
<MetricBar
+12
View File
@@ -958,6 +958,12 @@ func (m *Monitor) pollVMsAndContainersEfficient(ctx context.Context, instanceNam
diskFree := diskTotal - diskUsed
diskUsage := safePercentage(float64(diskUsed), float64(diskTotal))
// If VM shows 0 disk usage but has allocated disk, it's likely guest agent issue
// Set to -1 to indicate "unknown" rather than showing misleading 0%
if res.Type == "qemu" && diskUsed == 0 && diskTotal > 0 && res.Status == "running" {
diskUsage = -1
}
// For running VMs, try to get filesystem info from guest agent
if res.Status == "running" {
// First check if agent is enabled by getting VM status
@@ -1355,6 +1361,12 @@ func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, cli
diskFree := diskTotal - diskUsed
diskUsage := safePercentage(float64(diskUsed), float64(diskTotal))
// If VM shows 0 disk usage but has allocated disk, it's likely guest agent issue
// Set to -1 to indicate "unknown" rather than showing misleading 0%
if diskUsed == 0 && diskTotal > 0 && vm.Status == "running" {
diskUsage = -1
}
// If VM has guest agent enabled and is running, try to get filesystem info
if vm.Agent > 0 && vm.Status == "running" {
log.Debug().