Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Align frontend unified-resources types with omitempty serialization

rcourtman1f20ce5dd826
diff --git a/frontend-modern/src/components/Workloads/DrawerDiskListCard.tsx b/frontend-modern/src/components/Workloads/DrawerDiskListCard.tsx
index ca985facd3..f6c0ab67e1 100644
--- a/frontend-modern/src/components/Workloads/DrawerDiskListCard.tsx
+++ b/frontend-modern/src/components/Workloads/DrawerDiskListCard.tsx
@@ -17,11 +17,14 @@ export interface DrawerDiskListItem {
}
const getDiskUsagePercent = (disk: Disk): number => {
- if (disk.total > 0 && Number.isFinite(disk.used)) {
- return (disk.used / disk.total) * 100;
+ const total = disk.total ?? 0;
+ const used = disk.used ?? 0;
+ if (total > 0 && Number.isFinite(used)) {
+ return (used / total) * 100;
}
- if (Number.isFinite(disk.usage)) {
- return disk.usage <= 1 ? disk.usage * 100 : disk.usage;
+ const usage = disk.usage;
+ if (typeof usage === 'number' && Number.isFinite(usage)) {
+ return usage <= 1 ? usage * 100 : usage;
}
return 0;
};
diff --git a/frontend-modern/src/components/Workloads/diskListModel.ts b/frontend-modern/src/components/Workloads/diskListModel.ts
index 0308db94e1..1d3cf9e4c9 100644
--- a/frontend-modern/src/components/Workloads/diskListModel.ts
+++ b/frontend-modern/src/components/Workloads/diskListModel.ts
@@ -25,11 +25,12 @@ export const hasWorkloadsDiskCapacity = (disk: Disk): boolean =>
typeof disk.total === 'number' && disk.total > 0;
export const getWorkloadsDiskUsagePercent = (disk: Disk): number => {
- if (!hasWorkloadsDiskCapacity(disk)) {
+ const total = disk.total ?? 0;
+ if (total <= 0) {
return 0;
}
- return (disk.used / disk.total) * 100;
+ return ((disk.used ?? 0) / total) * 100;
};
export const getWorkloadsDiskLabel = (disk: Disk): string =>
@@ -40,7 +41,7 @@ export const getWorkloadsDiskLabelTitle = (label: string): string | undefined =>
export const getWorkloadsDiskUsageText = (disk: Disk): string =>
hasWorkloadsDiskCapacity(disk)
- ? `${formatBytes(disk.used)}/${formatBytes(disk.total)}`
+ ? `${formatBytes(disk.used ?? 0)}/${formatBytes(disk.total ?? 0)}`
: 'Usage unavailable';
export const getWorkloadsDiskUsagePercentLabel = (disk: Disk): string =>
diff --git a/frontend-modern/src/components/Workloads/stackedDiskBarModel.ts b/frontend-modern/src/components/Workloads/stackedDiskBarModel.ts
index 7ee62c40a9..f7d1f735cc 100644
--- a/frontend-modern/src/components/Workloads/stackedDiskBarModel.ts
+++ b/frontend-modern/src/components/Workloads/stackedDiskBarModel.ts
@@ -100,11 +100,13 @@ const SEGMENT_COLORS = [
];
function getDiskUsagePercent(disk: Disk): number {
- if (disk.total > 0) {
- return (disk.used / disk.total) * 100;
+ const total = disk.total ?? 0;
+ if (total > 0) {
+ return ((disk.used ?? 0) / total) * 100;
}
- if (Number.isFinite(disk.usage)) {
- return disk.usage <= 1 ? disk.usage * 100 : disk.usage;
+ const usage = disk.usage;
+ if (typeof usage === 'number' && Number.isFinite(usage)) {
+ return usage <= 1 ? usage * 100 : usage;
}
return 0;
}
@@ -189,21 +191,21 @@ function buildTooltipContent(
: getStackedDiskColor(percentValue, index, options.thresholds),
label: getDiskLabel(disk, index),
percent: formatPercent(percentValue),
- total: formatBytes(disk.total),
- used: formatBytes(disk.used),
+ total: formatBytes(disk.total ?? 0),
+ used: formatBytes(disk.used ?? 0),
};
});
}
- if (options.aggregateDisk && options.aggregateDisk.total > 0) {
+ if (options.aggregateDisk && (options.aggregateDisk.total ?? 0) > 0) {
const percentValue = getDiskUsagePercent(options.aggregateDisk);
return [
{
color: getMetricColorRgba(percentValue, 'disk', options.thresholds),
label: 'Total',
percent: formatPercent(percentValue),
- total: formatBytes(options.aggregateDisk.total),
- used: formatBytes(options.aggregateDisk.used),
+ total: formatBytes(options.aggregateDisk.total ?? 0),
+ used: formatBytes(options.aggregateDisk.used ?? 0),
},
];
}
@@ -223,8 +225,8 @@ function getMaxDiskInfo(disks: Disk[]): StackedDiskMaxInfo | null {
maxInfo = {
label: getDiskLabel(disk, index),
percent,
- total: disk.total,
- used: disk.used,
+ total: disk.total ?? 0,
+ used: disk.used ?? 0,
};
}
}
@@ -306,7 +308,7 @@ export function buildStackedDiskBarPresentation(
disk,
diskUsagePercent,
index,
- widthPercent: Math.min((disk.used / totalCapacity) * 100, 100),
+ widthPercent: Math.min(((disk.used ?? 0) / totalCapacity) * 100, 100),
};
})
: [];
@@ -322,7 +324,7 @@ export function buildStackedDiskBarPresentation(
percent,
percentLabel,
shortLabel,
- title: `${label}: ${percentLabel} (${formatBytes(disk.used)}/${formatBytes(disk.total)})`,
+ title: `${label}: ${percentLabel} (${formatBytes(disk.used ?? 0)}/${formatBytes(disk.total ?? 0)})`,
};
});
const verticalBars: StackedDiskVerticalBar[] = verticalBarsMode
@@ -332,7 +334,7 @@ export function buildStackedDiskBarPresentation(
return {
color: getMetricColorRgba(percent, 'disk', props.thresholds),
fillPercent: Math.max(0, Math.min(percent, 100)),
- title: `${label}: ${formatPercent(percent)} (${formatBytes(disk.used)}/${formatBytes(disk.total)})`,
+ title: `${label}: ${formatPercent(percent)} (${formatBytes(disk.used ?? 0)}/${formatBytes(disk.total ?? 0)})`,
};
})
: [];
diff --git a/frontend-modern/src/components/Workloads/useGuestRowState.ts b/frontend-modern/src/components/Workloads/useGuestRowState.ts
index 0ded8aea40..db708f1f52 100644
--- a/frontend-modern/src/components/Workloads/useGuestRowState.ts
+++ b/frontend-modern/src/components/Workloads/useGuestRowState.ts
@@ -219,14 +219,16 @@ export function useGuestRowState(props: GuestRowProps) {
});
const diskPercent = createMemo(() => {
- if (!props.guest.disk || props.guest.disk.total === 0) return 0;
- if (props.guest.disk.usage === -1) return -1;
- return (props.guest.disk.used / props.guest.disk.total) * 100;
+ const disk = props.guest.disk;
+ const total = disk?.total ?? 0;
+ if (!disk || total === 0) return 0;
+ if (disk.usage === -1) return -1;
+ return ((disk.used ?? 0) / total) * 100;
});
const hasDiskUsage = createMemo(() => {
if (!props.guest.disk) return false;
- if (props.guest.disk.total <= 0) return false;
+ if ((props.guest.disk.total ?? 0) <= 0) return false;
return diskPercent() !== -1;
});
diff --git a/frontend-modern/src/components/shared/cards/DisksCard.tsx b/frontend-modern/src/components/shared/cards/DisksCard.tsx
index 6cebe03186..8577f09cc6 100644
--- a/frontend-modern/src/components/shared/cards/DisksCard.tsx
+++ b/frontend-modern/src/components/shared/cards/DisksCard.tsx
@@ -1,6 +1,6 @@
import { Component, For, Show } from 'solid-js';
import { Disk } from '@/types/api';
-import { formatBytes } from '@/utils/format';
+import { formatBytes, type NormalizedDisk } from '@/utils/format';
import { getMetricColorRgba, getMetricTextColorClass } from '@/utils/metricThresholds';
import { InfoCardFrame } from '@/components/shared/InfoCardFrame';
import { StackedDiskBar } from '@/components/Workloads/StackedDiskBar';
@@ -12,7 +12,7 @@ interface DisksCardProps {
export const DisksCard: Component<DisksCardProps> = (props) => {
if (!props.disks || props.disks.length === 0) return null;
- const aggregateDisk = (): Disk | null => {
+ const aggregateDisk = (): NormalizedDisk | null => {
const total = props.disks?.reduce((sum, disk) => sum + (disk.total || 0), 0) ?? 0;
const used = props.disks?.reduce((sum, disk) => sum + (disk.used || 0), 0) ?? 0;
if (total <= 0 && used <= 0) return null;
@@ -52,7 +52,9 @@ export const DisksCard: Component<DisksCardProps> = (props) => {
<div class="max-h-[140px] overflow-y-auto custom-scrollbar space-y-2">
<For each={props.disks}>
{(disk) => {
- const usagePercent = disk.total > 0 ? (disk.used / disk.total) * 100 : 0;
+ const total = disk.total ?? 0;
+ const used = disk.used ?? 0;
+ const usagePercent = total > 0 ? (used / total) * 100 : 0;
const barColor = getMetricColorRgba(usagePercent, 'disk');
const textColor = getMetricTextColorClass(usagePercent, 'disk');
return (
@@ -65,7 +67,7 @@ export const DisksCard: Component<DisksCardProps> = (props) => {
<span class={`font-medium ${textColor}`}>{usagePercent.toFixed(0)}%</span>
<span class="text-muted">·</span>
<span class="text-muted">
- {formatBytes(disk.used)} / {formatBytes(disk.total)}
+ {formatBytes(used)} / {formatBytes(total)}
</span>
</span>
</div>
diff --git a/frontend-modern/src/components/shared/cards/RaidCard.tsx b/frontend-modern/src/components/shared/cards/RaidCard.tsx
index d1e2a01045..726a1d92eb 100644
--- a/frontend-modern/src/components/shared/cards/RaidCard.tsx
+++ b/frontend-modern/src/components/shared/cards/RaidCard.tsx
@@ -30,10 +30,9 @@ export const RaidCard: Component<RaidCardProps> = (props) => {
const variant = () => getRaidStateVariant(array.state);
const stateText = () => (array.state || '').trim() || 'unknown';
const levelText = () => (array.level || '').trim() || 'unknown';
+ const rebuildPercent = () => array.rebuildPercent ?? 0;
const rebuilding = () =>
- Number.isFinite(array.rebuildPercent) &&
- array.rebuildPercent > 0 &&
- array.rebuildPercent < 100;
+ Number.isFinite(rebuildPercent()) && rebuildPercent() > 0 && rebuildPercent() < 100;
return (
<div class="rounded border border-dashed border-border p-2 overflow-hidden">
@@ -66,7 +65,7 @@ export const RaidCard: Component<RaidCardProps> = (props) => {
<div class="mt-2 text-[10px] text-muted">
Rebuild:{' '}
<span class="font-medium text-base-content">
- {Math.round(array.rebuildPercent)}%
+ {Math.round(rebuildPercent())}%
</span>
<Show when={array.rebuildSpeed}>
<span class="text-muted"> · </span>
diff --git a/frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsGuestData.ts b/frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsGuestData.ts
index 56fee75712..86e59fb2ac 100644
--- a/frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsGuestData.ts
+++ b/frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsGuestData.ts
@@ -155,7 +155,9 @@ export function useThresholdsGuestData(inputs: ThresholdsDataInputs) {
groupKey: guestIdentity
? `${guestName} · ${guestIdentity.instance}/${guestIdentity.vmid}`
: guestName,
- instance: disk.type || '',
+ // Unified payloads carry the filesystem under `filesystem`; the
+ // legacy state payload uses `type`.
+ instance: disk.filesystem || disk.type || '',
vmid: guestIdentity?.vmid,
status: guest.status,
hasOverride: hasCustomThresholds || Boolean(override?.disabled),
diff --git a/frontend-modern/src/features/standalone/AgentsMachinesTable.tsx b/frontend-modern/src/features/standalone/AgentsMachinesTable.tsx
index 1e73f4dd1a..f5cdeaf182 100644
--- a/frontend-modern/src/features/standalone/AgentsMachinesTable.tsx
+++ b/frontend-modern/src/features/standalone/AgentsMachinesTable.tsx
@@ -602,8 +602,9 @@ const AgentMachineRaidCell: Component<{
<div class="max-h-[300px] space-y-2 overflow-y-auto pr-1">
<For each={shownArrays()}>
{(array, index) => {
- const rebuilding = () =>
- Number.isFinite(array.rebuildPercent) && array.rebuildPercent > 0;
+ const rebuildPercent = () => array.rebuildPercent ?? 0;
+ const devices = () => array.devices ?? [];
+ const rebuilding = () => Number.isFinite(rebuildPercent()) && rebuildPercent() > 0;
return (
<div class="min-w-0" classList={{ 'border-t border-border pt-2': index() > 0 }}>
@@ -659,13 +660,13 @@ const AgentMachineRaidCell: Component<{
<div class="mb-0.5 flex items-center justify-between gap-3 text-[9px]">
<span class="text-amber-600 dark:text-amber-400">Rebuilding</span>
<span class="font-mono text-base-content">
- {Math.round(array.rebuildPercent)}%
+ {Math.round(rebuildPercent())}%
</span>
</div>
<div class="h-1 overflow-hidden rounded-full bg-surface-alt">
<div
class="h-full rounded-full bg-amber-500"
- style={{ width: rebuildWidth(array.rebuildPercent) }}
+ style={{ width: rebuildWidth(rebuildPercent()) }}
/>
</div>
<Show when={array.rebuildSpeed}>
@@ -674,9 +675,9 @@ const AgentMachineRaidCell: Component<{
</div>
</Show>
- <Show when={array.devices.length > 0}>
+ <Show when={devices().length > 0}>
<div class="mt-1.5 flex flex-wrap gap-1">
- <For each={array.devices.slice(0, 12)}>
+ <For each={devices().slice(0, 12)}>
{(device) => (
<span
class={`inline-flex max-w-full items-center truncate rounded border px-1.5 py-0.5 text-[9px] font-medium ${getRaidDeviceBadgeClass(device)}`}
@@ -686,9 +687,9 @@ const AgentMachineRaidCell: Component<{
</span>
)}
</For>
- <Show when={array.devices.length > 12}>
+ <Show when={devices().length > 12}>
<span class="rounded border border-border px-1.5 py-0.5 text-[9px] text-muted">
- +{array.devices.length - 12}
+ +{devices().length - 12}
</span>
</Show>
</div>
diff --git a/frontend-modern/src/features/standalone/agentMachineTableModel.ts b/frontend-modern/src/features/standalone/agentMachineTableModel.ts
index 1ba11593c6..f51f123539 100644
--- a/frontend-modern/src/features/standalone/agentMachineTableModel.ts
+++ b/frontend-modern/src/features/standalone/agentMachineTableModel.ts
@@ -824,7 +824,7 @@ export const matchesAgentMachineSearch = (
array.level,
array.state,
array.rebuildSpeed,
- ...array.devices.flatMap((device) => [device.device, device.state, device.slot]),
+ ...(array.devices ?? []).flatMap((device) => [device.device, device.state, device.slot]),
]),
);
appendSearchValues(values, [getAgentMachineRaidSummary(machine), ...sensorSearchValues(machine)]);
diff --git a/frontend-modern/src/types/api.ts b/frontend-modern/src/types/api.ts
index fd84ba1544..dde540bf4a 100644
--- a/frontend-modern/src/types/api.ts
+++ b/frontend-modern/src/types/api.ts
@@ -605,8 +605,8 @@ export interface HostRAIDArray {
failedDevices: number;
spareDevices: number;
uuid?: string;
- devices: HostRAIDDevice[];
- rebuildPercent: number;
+ devices?: HostRAIDDevice[];
+ rebuildPercent?: number;
rebuildSpeed?: string;
}
@@ -1046,11 +1046,11 @@ export interface PBSBackupJob {
id: string;
store: string;
type: string;
- vmid: string;
+ vmid?: string;
lastBackup: string;
- nextRun: string;
+ nextRun?: string;
status: string;
- error: string;
+ error?: string;
}
export interface PBSSyncJob {
@@ -1059,8 +1059,8 @@ export interface PBSSyncJob {
remote: string;
status: string;
lastSync: string;
- nextRun: string;
- error: string;
+ nextRun?: string;
+ error?: string;
}
export interface PBSVerifyJob {
@@ -1068,8 +1068,8 @@ export interface PBSVerifyJob {
store: string;
status: string;
lastVerify: string;
- nextRun: string;
- error: string;
+ nextRun?: string;
+ error?: string;
}
export interface PBSPruneJob {
@@ -1077,8 +1077,8 @@ export interface PBSPruneJob {
store: string;
status: string;
lastPrune: string;
- nextRun: string;
- error: string;
+ nextRun?: string;
+ error?: string;
}
export interface PBSGarbageJob {
@@ -1086,9 +1086,9 @@ export interface PBSGarbageJob {
store: string;
status: string;
lastGarbage: string;
- nextRun: string;
- removedBytes: number;
- error: string;
+ nextRun?: string;
+ removedBytes?: number;
+ error?: string;
}
export interface PBSJobHealthFreshness {
@@ -1141,13 +1141,18 @@ export interface Memory {
swapTotal?: number;
}
+// Models both the legacy state payload (models.Disk, numerics always present,
+// filesystem under `type`) and the unified resources facet (DiskInfo, every
+// field omitempty so zero values arrive absent, filesystem under `filesystem`).
+// Consumers must default absent numerics rather than assume presence (#1663).
export interface Disk {
- total: number;
- used: number;
- free: number;
- usage: number;
+ total?: number;
+ used?: number;
+ free?: number;
+ usage?: number;
mountpoint?: string;
type?: string;
+ filesystem?: string;
device?: string;
}
diff --git a/frontend-modern/src/utils/format.ts b/frontend-modern/src/utils/format.ts
index 5e13d39bd1..28112bbcdf 100644
--- a/frontend-modern/src/utils/format.ts
+++ b/frontend-modern/src/utils/format.ts
@@ -316,11 +316,23 @@ export function getShortImageName(fullImage: string | undefined): string {
return parts.at(-1) || cleanImage || '—';
}
+/**
+ * A Disk whose numeric fields are guaranteed present. The wire type leaves
+ * them optional (the unified resources payload omits zero values); these
+ * helpers compute and default them so consumers can render without guards.
+ */
+export type NormalizedDisk = Disk & {
+ total: number;
+ used: number;
+ free: number;
+ usage: number;
+};
+
/**
* Normalize raw disk objects (from API/agent) into proper Disk[].
* Calculates `usage` from used/total and defaults missing fields.
*/
-export function normalizeDiskArray(disks?: DiskInput[]): Disk[] | undefined {
+export function normalizeDiskArray(disks?: DiskInput[]): NormalizedDisk[] | undefined {
if (!disks || disks.length === 0) return undefined;
const normalized = disks.filter(shouldDisplayDisk).map((d) => {
const total = d.total ?? 0;
@@ -342,7 +354,7 @@ export function normalizeDiskArray(disks?: DiskInput[]): Disk[] | undefined {
export function getResourceDiskSummary(
resource: Pick<Resource, 'agent' | 'disk'>,
-): Disk | undefined {
+): NormalizedDisk | undefined {
if (resource.disk) {
const total = resource.disk.total ?? 0;
const used = resource.disk.used ?? 0;
diff --git a/frontend-modern/src/utils/searchQuery.ts b/frontend-modern/src/utils/searchQuery.ts
index 06e65cf262..e023ae1719 100644
--- a/frontend-modern/src/utils/searchQuery.ts
+++ b/frontend-modern/src/utils/searchQuery.ts
@@ -150,7 +150,7 @@ function evaluateMetricCondition(guest: FilterableItem, condition: MetricConditi
value = 'memory' in guest && guest.memory ? guest.memory.usage : 0;
break;
case 'disk':
- value = 'disk' in guest && guest.disk ? guest.disk.usage : 0;
+ value = 'disk' in guest && guest.disk ? (guest.disk.usage ?? 0) : 0;
break;
case 'uptime':
// Uptime in seconds (only for running VMs/containers)