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.

Add aggregate disk summary to machine details

rcourtman886c6055339c
diff --git a/frontend-modern/src/components/Infrastructure/__tests__/ResourceDetailDrawer.machine-history.test.tsx b/frontend-modern/src/components/Infrastructure/__tests__/ResourceDetailDrawer.machine-history.test.tsx
index 8b333ab14e..1713361174 100644
--- a/frontend-modern/src/components/Infrastructure/__tests__/ResourceDetailDrawer.machine-history.test.tsx
+++ b/frontend-modern/src/components/Infrastructure/__tests__/ResourceDetailDrawer.machine-history.test.tsx
@@ -52,6 +52,12 @@ vi.mock('@/components/Discovery/DiscoveryTab', () => ({
),
}));
+vi.mock('@/components/Workloads/StackedDiskBar', () => ({
+ StackedDiskBar: (props: { mode?: string }) => (
+ <div data-testid="stacked-disk-bar" data-mode={props.mode} />
+ ),
+}));
+
const resource = (overrides: Partial<Resource>): Resource =>
({
id: overrides.id ?? 'agent-1',
diff --git a/frontend-modern/src/components/shared/cards/DisksCard.tsx b/frontend-modern/src/components/shared/cards/DisksCard.tsx
index 5dc77865df..6821776f09 100644
--- a/frontend-modern/src/components/shared/cards/DisksCard.tsx
+++ b/frontend-modern/src/components/shared/cards/DisksCard.tsx
@@ -1,7 +1,8 @@
-import { Component, For } from 'solid-js';
+import { Component, For, Show } from 'solid-js';
import { Disk } from '@/types/api';
import { formatBytes } from '@/utils/format';
import { getMetricColorRgba, getMetricTextColorClass } from '@/utils/metricThresholds';
+import { StackedDiskBar } from '@/components/Workloads/StackedDiskBar';
interface DisksCardProps {
disks?: Disk[];
@@ -10,11 +11,43 @@ interface DisksCardProps {
export const DisksCard: Component<DisksCardProps> = (props) => {
if (!props.disks || props.disks.length === 0) return null;
+ const aggregateDisk = (): Disk | 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;
+ return {
+ total,
+ used,
+ free: Math.max(total - used, 0),
+ usage: total > 0 ? used / total : 0,
+ mountpoint: 'Total',
+ };
+ };
+ const aggregateUsagePercent = () => {
+ const aggregate = aggregateDisk();
+ return aggregate && aggregate.total > 0 ? (aggregate.used / aggregate.total) * 100 : 0;
+ };
+
return (
<div class="rounded border border-border bg-surface p-3 shadow-sm">
<div class="text-[11px] font-medium uppercase tracking-wide text-base-content mb-2">
Disks
</div>
+ <Show when={aggregateDisk()}>
+ {(aggregate) => (
+ <div class="mb-3 space-y-1.5 border-b border-border pb-3" data-testid="disks-card-total">
+ <div class="flex justify-between gap-2 text-[10px]">
+ <span class="text-muted">Total Usage</span>
+ <span
+ class={`font-medium ${getMetricTextColorClass(aggregateUsagePercent(), 'disk')}`}
+ >
+ {formatBytes(aggregate().used)} / {formatBytes(aggregate().total)}
+ </span>
+ </div>
+ <StackedDiskBar disks={props.disks} aggregateDisk={aggregate()} mode="aggregate" />
+ </div>
+ )}
+ </Show>
<div class="max-h-[140px] overflow-y-auto custom-scrollbar space-y-2">
<For each={props.disks}>
{(disk) => {
diff --git a/frontend-modern/src/components/shared/cards/__tests__/DisksCard.test.tsx b/frontend-modern/src/components/shared/cards/__tests__/DisksCard.test.tsx
new file mode 100644
index 0000000000..acd11805bb
--- /dev/null
+++ b/frontend-modern/src/components/shared/cards/__tests__/DisksCard.test.tsx
@@ -0,0 +1,63 @@
+import { cleanup, render, screen } from '@solidjs/testing-library';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import { DisksCard } from '../DisksCard';
+
+vi.mock('@/components/Workloads/StackedDiskBar', () => ({
+ StackedDiskBar: (props: {
+ disks?: unknown[];
+ aggregateDisk?: { total?: number; used?: number };
+ mode?: string;
+ }) => (
+ <div
+ data-testid="stacked-disk-bar"
+ data-mode={props.mode}
+ data-disk-count={props.disks?.length ?? 0}
+ data-total={props.aggregateDisk?.total}
+ data-used={props.aggregateDisk?.used}
+ />
+ ),
+}));
+
+afterEach(() => {
+ cleanup();
+ vi.clearAllMocks();
+});
+
+describe('DisksCard', () => {
+ it('renders an aggregate disk usage summary before individual mounts', () => {
+ render(() => (
+ <DisksCard
+ disks={[
+ {
+ mountpoint: '/',
+ total: 100,
+ used: 60,
+ free: 40,
+ usage: 0.6,
+ },
+ {
+ mountpoint: '/data',
+ total: 300,
+ used: 120,
+ free: 180,
+ usage: 0.4,
+ },
+ ]}
+ />
+ ));
+
+ expect(screen.getByTestId('disks-card-total')).toHaveTextContent('Total Usage');
+ expect(screen.getByTestId('stacked-disk-bar')).toHaveAttribute('data-mode', 'aggregate');
+ expect(screen.getByTestId('stacked-disk-bar')).toHaveAttribute('data-disk-count', '2');
+ expect(screen.getByTestId('stacked-disk-bar')).toHaveAttribute('data-total', '400');
+ expect(screen.getByTestId('stacked-disk-bar')).toHaveAttribute('data-used', '180');
+ expect(screen.getByText('/')).toBeInTheDocument();
+ expect(screen.getByText('/data')).toBeInTheDocument();
+ });
+
+ it('renders nothing when no disks are available', () => {
+ const { container } = render(() => <DisksCard disks={[]} />);
+
+ expect(container).toBeEmptyDOMElement();
+ });
+});