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.

Fix Docker host overview metrics

rcourtman2588ed8baa8c
diff --git a/frontend-modern/src/features/docker/DockerHostsTable.tsx b/frontend-modern/src/features/docker/DockerHostsTable.tsx
index b10d279ec0..8433e5e4a8 100644
--- a/frontend-modern/src/features/docker/DockerHostsTable.tsx
+++ b/frontend-modern/src/features/docker/DockerHostsTable.tsx
@@ -1,7 +1,10 @@
import { For, Show, type Component, type JSX } from 'solid-js';
import { StatusDot } from '@/components/shared/StatusDot';
+import { ResponsiveMetricCell } from '@/components/shared/responsive';
import { TableCard } from '@/components/shared/TableCard';
import { TableCardHeader } from '@/components/shared/TableCardHeader';
+import { StackedMemoryBar } from '@/components/Workloads/StackedMemoryBar';
+import { StackedDiskBar } from '@/components/Workloads/StackedDiskBar';
import {
Table,
TableBody,
@@ -12,6 +15,8 @@ import {
} from '@/components/shared/Table';
import { getSimpleStatusIndicator } from '@/utils/status';
import { asTrimmedString } from '@/utils/stringUtils';
+import { normalizeDiskArray } from '@/utils/format';
+import { buildMetricKeyForUnifiedResource } from '@/utils/metricsKeys';
import {
PLATFORM_TABLE_BODY_CLASS,
PLATFORM_TABLE_CARD_CLASS,
@@ -25,23 +30,18 @@ import {
getPlatformTableHeadClass,
type PlatformResourceStatusFilter,
} from '@/features/platformPage/sharedPlatformPage';
+import type { Disk } from '@/types/api';
import type { Resource } from '@/types/resource';
// Docker / Podman hosts are container hosts, not generic Pulse Agents.
-// The operator columns that matter are runtime (Docker vs Podman),
-// runtime version, container count, and Swarm role, alongside the
+// The operator columns that matter are runtime version, container count,
+// and Swarm role, alongside the
// usual CPU / Memory / Disk / Uptime / Temperature from the agent
// telemetry. The generic infrastructure table renders the metrics fine
// but omits the runtime context that distinguishes a Docker host from
// any other agent. This bespoke table reuses canonical shared
// primitives and surfaces the Docker-native columns.
-const formatPercent = (percent?: number): JSX.Element => {
- if (typeof percent !== 'number' || Number.isNaN(percent))
- return <span class="text-muted">—</span>;
- return <span class="tabular-nums">{percent.toFixed(1)}%</span>;
-};
-
const formatUptime = (seconds: number | undefined): string => {
if (!seconds || seconds <= 0) return '—';
const days = Math.floor(seconds / 86_400);
@@ -57,11 +57,40 @@ const formatTemperature = (celsius: number | undefined): JSX.Element => {
return <span class="tabular-nums">{celsius.toFixed(1)}°C</span>;
};
-const runtimeLabel = (runtime: string | undefined): string => {
- const normalized = (runtime || '').trim().toLowerCase();
- if (normalized === 'docker') return 'Docker';
- if (normalized === 'podman') return 'Podman';
- return runtime || '—';
+const metricFallback = () => (
+ <div class="flex justify-center">
+ <span class="text-xs text-muted" aria-hidden="true">
+ —
+ </span>
+ </div>
+);
+
+const finiteMetric = (value: number | undefined): number | undefined =>
+ typeof value === 'number' && Number.isFinite(value) ? value : undefined;
+
+const percentFromMetric = (metric: Resource['cpu'] | undefined): number | undefined =>
+ finiteMetric(metric?.current);
+
+const memoryTotalFor = (host: Resource): number =>
+ finiteMetric(host.memory?.total) ?? finiteMetric(host.agent?.memory?.total) ?? 0;
+
+const memoryUsedFor = (host: Resource): number =>
+ finiteMetric(host.memory?.used) ?? finiteMetric(host.agent?.memory?.used) ?? 0;
+
+const memoryPercentOnlyFor = (host: Resource): number | undefined => {
+ if (memoryTotalFor(host) > 0) return undefined;
+ return finiteMetric(host.memory?.current) ?? finiteMetric(host.agent?.memory?.usage);
+};
+
+const aggregateDiskFor = (host: Resource): Disk | undefined => {
+ if (!host.disk) return undefined;
+ const total = finiteMetric(host.disk.total) ?? 0;
+ const used = finiteMetric(host.disk.used) ?? 0;
+ const free = finiteMetric(host.disk.free) ?? (total > 0 ? Math.max(0, total - used) : 0);
+ const usage =
+ total > 0 && used > 0 ? (used / total) * 100 : (finiteMetric(host.disk.current) ?? 0);
+ if (total <= 0 && usage <= 0) return undefined;
+ return { total, used, free, usage };
};
export const DockerHostsTable: Component<{
@@ -116,13 +145,10 @@ export const DockerHostsTable: Component<{
>
<TableCard class={PLATFORM_TABLE_CARD_CLASS}>
<TableCardHeader title={props.title ?? 'Hosts'} />
- <Table class="min-w-full table-fixed text-xs md:min-w-[1040px]">
+ <Table class="min-w-full table-fixed text-xs md:min-w-[960px]">
<TableHeader>
<TableRow class={PLATFORM_TABLE_HEADER_ROW_CLASS}>
<TableHead class={getPlatformTableHeadClass()}>Host</TableHead>
- <TableHead class={`${getPlatformTableHeadClass()} hidden md:table-cell`}>
- Runtime
- </TableHead>
<TableHead class={`${getPlatformTableHeadClass()} hidden md:table-cell`}>
Version
</TableHead>
@@ -158,7 +184,6 @@ export const DockerHostsTable: Component<{
})
| undefined;
const name = () => asTrimmedString(host.name) || host.id;
- const runtime = () => runtimeLabel(docker()?.runtime);
const version = () => asTrimmedString(docker()?.runtimeVersion) || '—';
const containerCount = () => docker()?.containerCount ?? 0;
const swarmRole = () => {
@@ -166,6 +191,18 @@ export const DockerHostsTable: Component<{
return role ? role.charAt(0).toUpperCase() + role.slice(1) : '—';
};
const indicator = () => getSimpleStatusIndicator(host.status);
+ const canRenderMetrics = () => indicator().variant !== 'danger';
+ const metricsKey = () => buildMetricKeyForUnifiedResource(host);
+ const cpuPercent = () => percentFromMetric(host.cpu);
+ const memoryUsed = () => memoryUsedFor(host);
+ const memoryTotal = () => memoryTotalFor(host);
+ const memoryPercentOnly = () => memoryPercentOnlyFor(host);
+ const hasMemoryMetric = () =>
+ memoryTotal() > 0 || memoryPercentOnly() !== undefined;
+ const aggregateDisk = () => aggregateDiskFor(host);
+ const disks = () => normalizeDiskArray(host.agent?.disks);
+ const hasDiskMetric = () =>
+ aggregateDisk() !== undefined || (disks()?.length ?? 0) > 0;
return (
<TableRow class="text-[11px] sm:text-xs">
<TableCell class={getPlatformTableCellClass()}>
@@ -181,11 +218,6 @@ export const DockerHostsTable: Component<{
</span>
</div>
</TableCell>
- <TableCell
- class={`${getPlatformTableCellClass()} hidden text-base-content md:table-cell`}
- >
- {runtime()}
- </TableCell>
<TableCell
class={`${getPlatformTableCellClass()} hidden font-mono text-[11px] text-base-content md:table-cell`}
>
@@ -196,20 +228,39 @@ export const DockerHostsTable: Component<{
>
{containerCount()}
</TableCell>
- <TableCell
- class={`${getPlatformTableCellClass('right')} text-base-content`}
- >
- {formatPercent(host.cpu?.current)}
+ <TableCell class={getPlatformTableCellClass('right')}>
+ <ResponsiveMetricCell
+ class="w-full"
+ value={cpuPercent() ?? 0}
+ type="cpu"
+ resourceId={metricsKey()}
+ isRunning={canRenderMetrics() && cpuPercent() !== undefined}
+ showMobile={false}
+ />
</TableCell>
- <TableCell
- class={`${getPlatformTableCellClass('right')} text-base-content`}
- >
- {formatPercent(host.memory?.current)}
+ <TableCell class={getPlatformTableCellClass('right')}>
+ <Show
+ when={canRenderMetrics() && hasMemoryMetric()}
+ fallback={metricFallback()}
+ >
+ <StackedMemoryBar
+ used={memoryUsed()}
+ total={memoryTotal()}
+ percentOnly={memoryPercentOnly()}
+ />
+ </Show>
</TableCell>
- <TableCell
- class={`${getPlatformTableCellClass('right')} text-base-content`}
- >
- {formatPercent(host.disk?.current)}
+ <TableCell class={getPlatformTableCellClass('right')}>
+ <Show
+ when={canRenderMetrics() && hasDiskMetric()}
+ fallback={metricFallback()}
+ >
+ <StackedDiskBar
+ mode={(disks()?.length ?? 0) > 1 ? 'vertical-bars' : undefined}
+ disks={disks()}
+ aggregateDisk={aggregateDisk()}
+ />
+ </Show>
</TableCell>
<TableCell
class={`${getPlatformTableCellClass('right')} hidden text-base-content md:table-cell`}
diff --git a/frontend-modern/src/features/docker/__tests__/DockerHostsTable.test.tsx b/frontend-modern/src/features/docker/__tests__/DockerHostsTable.test.tsx
new file mode 100644
index 0000000000..39214eb006
--- /dev/null
+++ b/frontend-modern/src/features/docker/__tests__/DockerHostsTable.test.tsx
@@ -0,0 +1,123 @@
+import { cleanup, render, screen } from '@solidjs/testing-library';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+
+import type { Disk } from '@/types/api';
+import type { Resource } from '@/types/resource';
+import { DockerHostsTable } from '../DockerHostsTable';
+
+vi.mock('@/components/shared/responsive', () => ({
+ ResponsiveMetricCell: (props: { type: string; isRunning?: boolean; resourceId?: string }) => (
+ <div
+ data-testid={`responsive-${props.type}-metric`}
+ data-resource-id={props.resourceId ?? ''}
+ data-running={String(props.isRunning)}
+ />
+ ),
+}));
+
+vi.mock('@/components/Workloads/StackedMemoryBar', () => ({
+ StackedMemoryBar: (props: { used: number; total: number; percentOnly?: number }) => (
+ <div
+ data-testid="stacked-memory-bar"
+ data-used={String(props.used)}
+ data-total={String(props.total)}
+ data-percent-only={String(props.percentOnly ?? '')}
+ />
+ ),
+}));
+
+vi.mock('@/components/Workloads/StackedDiskBar', () => ({
+ StackedDiskBar: (props: { disks?: Disk[]; aggregateDisk?: Disk; mode?: string }) => (
+ <div
+ data-testid="stacked-disk-bar"
+ data-mode={props.mode ?? ''}
+ data-disks={String(props.disks?.length ?? 0)}
+ data-aggregate-usage={String(props.aggregateDisk?.usage ?? '')}
+ />
+ ),
+}));
+
+const makeDockerHost = (overrides: Partial<Resource> = {}): Resource => ({
+ id: 'agent:docker-01',
+ name: 'docker-01',
+ displayName: 'docker-01',
+ platformId: 'homelab',
+ platformType: 'docker',
+ sourceType: 'agent',
+ status: 'degraded',
+ type: 'agent',
+ lastSeen: 1_700_000_000_000,
+ cpu: { current: 42 },
+ memory: { total: 8_000, used: 3_200, free: 4_800, current: 40 },
+ disk: { total: 20_000, used: 12_500, free: 7_500, current: 62.5 },
+ agent: {
+ disks: [
+ { device: '/dev/sda1', mountpoint: '/', total: 10_000, used: 6_000, free: 4_000 },
+ {
+ device: '/dev/sdb1',
+ mountpoint: '/var/lib/docker',
+ total: 10_000,
+ used: 6_500,
+ free: 3_500,
+ },
+ ],
+ },
+ docker: {
+ runtimeVersion: '27.5.1',
+ containerCount: 12,
+ } as NonNullable<Resource['docker']> & { runtimeVersion?: string; containerCount?: number },
+ ...overrides,
+});
+
+afterEach(() => {
+ cleanup();
+ vi.clearAllMocks();
+});
+
+describe('DockerHostsTable', () => {
+ it('renders Docker hosts with a single-line Version column and shared metric bars', () => {
+ render(() => (
+ <DockerHostsTable
+ resources={[makeDockerHost()]}
+ emptyIcon={<span />}
+ emptyTitle="No Docker hosts"
+ emptyDescription="No hosts"
+ showToolbar={false}
+ />
+ ));
+
+ expect(screen.getByRole('columnheader', { name: 'Version' })).toBeInTheDocument();
+ expect(screen.queryByRole('columnheader', { name: 'Runtime' })).not.toBeInTheDocument();
+ expect(screen.getByText('27.5.1')).toBeInTheDocument();
+ expect(screen.queryByText('Docker')).not.toBeInTheDocument();
+ expect(screen.getByTestId('responsive-cpu-metric')).toHaveAttribute('data-running', 'true');
+ expect(screen.getByTestId('stacked-memory-bar')).toHaveAttribute('data-used', '3200');
+ expect(screen.getByTestId('stacked-memory-bar')).toHaveAttribute('data-total', '8000');
+ expect(screen.getByTestId('stacked-disk-bar')).toHaveAttribute('data-mode', 'vertical-bars');
+ expect(screen.getByTestId('stacked-disk-bar')).toHaveAttribute('data-disks', '2');
+ });
+
+ it('uses percent-only memory and aggregate disk bars when capacity details are missing', () => {
+ render(() => (
+ <DockerHostsTable
+ resources={[
+ makeDockerHost({
+ status: 'online',
+ memory: { current: 55 },
+ disk: { current: 71 },
+ agent: undefined,
+ }),
+ ]}
+ emptyIcon={<span />}
+ emptyTitle="No Docker hosts"
+ emptyDescription="No hosts"
+ showToolbar={false}
+ />
+ ));
+
+ expect(screen.getByTestId('stacked-memory-bar')).toHaveAttribute('data-total', '0');
+ expect(screen.getByTestId('stacked-memory-bar')).toHaveAttribute('data-percent-only', '55');
+ expect(screen.getByTestId('stacked-disk-bar')).toHaveAttribute('data-disks', '0');
+ expect(screen.getByTestId('stacked-disk-bar')).toHaveAttribute('data-aggregate-usage', '71');
+ });
+});