Skip to content

Modern Docker Management, Designed for Everyone

feat: show container stats inline in table (#1359)

Kyle Mendelled7303f16ef6
diff --git a/frontend/messages/en.json b/frontend/messages/en.json
index 301c5a703..13074b565 100644
--- a/frontend/messages/en.json
+++ b/frontend/messages/en.json
@@ -340,6 +340,8 @@
"containers_nav_networks": "Networks",
"containers_nav_storage": "Storage",
"containers_ip_address": "IP Address",
+ "containers_cpu_usage": "CPU Usage",
+ "containers_memory_usage": "Memory Usage",
"containers_mac_address": "MAC Address",
"containers_aliases": "Aliases",
"containers_resource_metrics": "Resource Metrics",
diff --git a/frontend/src/lib/components/arcane-table/arcane-table.svelte b/frontend/src/lib/components/arcane-table/arcane-table.svelte
index 895145724..b7c08b3c0 100644
--- a/frontend/src/lib/components/arcane-table/arcane-table.svelte
+++ b/frontend/src/lib/components/arcane-table/arcane-table.svelte
@@ -56,7 +56,8 @@
persistKey,
customViewOptions,
customTableView,
- customSettings = $bindable<Record<string, unknown>>({})
+ customSettings = $bindable<Record<string, unknown>>({}),
+ columnVisibility = $bindable<VisibilityState>({})
}: {
items: Paginated<TData>;
requestOptions: SearchPaginationSortRequest;
@@ -85,10 +86,10 @@
]
>;
customSettings?: Record<string, unknown>;
+ columnVisibility?: VisibilityState;
} = $props();
let rowSelection = $state<RowSelectionState>({});
- let columnVisibility = $state<VisibilityState>({});
let columnFilters = $state<ColumnFiltersState>([]);
let sorting = $state<SortingState>([]);
let globalFilter = $state<string>('');
diff --git a/frontend/src/lib/utils/container-stats.utils.ts b/frontend/src/lib/utils/container-stats.utils.ts
new file mode 100644
index 000000000..20e113bfe
--- /dev/null
+++ b/frontend/src/lib/utils/container-stats.utils.ts
@@ -0,0 +1,27 @@
+import type { ContainerStats } from '$lib/types/container.type';
+
+export function calculateCPUPercent(stats: ContainerStats | null): number {
+ if (!stats?.cpu_stats || !stats?.precpu_stats) return 0;
+
+ const cpuDelta = stats.cpu_stats.cpu_usage.total_usage - (stats.precpu_stats.cpu_usage?.total_usage || 0);
+ const systemDelta = stats.cpu_stats.system_cpu_usage - (stats.precpu_stats.system_cpu_usage || 0);
+
+ if (systemDelta > 0 && cpuDelta > 0) {
+ const cpuPercent = (cpuDelta / systemDelta) * 100.0;
+ return Math.min(Math.max(cpuPercent, 0), 100);
+ }
+ return 0;
+}
+
+export function calculateMemoryPercent(stats: ContainerStats | null): number {
+ if (!stats?.memory_stats) return 0;
+
+ const usage = stats.memory_stats.usage || 0;
+ const limit = stats.memory_stats.limit || 0;
+
+ if (limit > 0) {
+ const percent = (usage / limit) * 100;
+ return Math.min(Math.max(percent, 0), 100);
+ }
+ return 0;
+}
diff --git a/frontend/src/routes/(app)/containers/components/container-stats-cell.svelte b/frontend/src/routes/(app)/containers/components/container-stats-cell.svelte
new file mode 100644
index 000000000..360f9d641
--- /dev/null
+++ b/frontend/src/routes/(app)/containers/components/container-stats-cell.svelte
@@ -0,0 +1,52 @@
+<script lang="ts">
+ import { Progress } from '$lib/components/ui/progress/index.js';
+ import { m } from '$lib/paraglide/messages';
+ import bytes from 'bytes';
+
+ interface Props {
+ value?: number;
+ limit?: number;
+ loading?: boolean;
+ stopped?: boolean;
+ type: 'cpu' | 'memory';
+ }
+
+ let { value, limit, loading = false, stopped = false, type }: Props = $props();
+
+ const memoryPercent = $derived.by(() => {
+ if (type !== 'memory' || !value || !limit || limit === 0) return undefined;
+ return (value / limit) * 100;
+ });
+
+ const memoryFormatted = $derived.by(() => {
+ if (type !== 'memory' || value === undefined) return undefined;
+ return bytes.format(value, { unitSeparator: ' ' });
+ });
+</script>
+
+{#if stopped}
+ <div class="text-muted-foreground text-xs">{m.common_na()}</div>
+{:else if loading}
+ <div class="flex items-center gap-2">
+ <div class="bg-muted h-1.5 flex-1 animate-pulse rounded-full"></div>
+ <div class="bg-muted h-3 w-16 animate-pulse rounded"></div>
+ </div>
+{:else if type === 'memory' && memoryFormatted}
+ <div class="flex items-center gap-2">
+ {#if memoryPercent !== undefined}
+ <Progress value={memoryPercent} max={100} class="h-1.5 flex-1" />
+ {/if}
+ <span class="text-foreground min-w-16 text-right text-xs font-medium tabular-nums">
+ {memoryFormatted}
+ </span>
+ </div>
+{:else if type === 'cpu' && value !== undefined}
+ <div class="flex items-center gap-2">
+ <Progress {value} max={100} class="h-1.5 flex-1" />
+ <span class="text-foreground min-w-10 text-right text-xs font-medium tabular-nums">
+ {value.toFixed(1)}%
+ </span>
+ </div>
+{:else}
+ <div class="text-muted-foreground text-xs">—</div>
+{/if}
diff --git a/frontend/src/routes/(app)/containers/components/container-stats-manager.svelte.ts b/frontend/src/routes/(app)/containers/components/container-stats-manager.svelte.ts
new file mode 100644
index 000000000..737313c41
--- /dev/null
+++ b/frontend/src/routes/(app)/containers/components/container-stats-manager.svelte.ts
@@ -0,0 +1,89 @@
+import { createContainerStatsWebSocket } from '../../../../lib/utils/ws';
+import type { ContainerStats } from '$lib/types/container.type';
+import { calculateCPUPercent, calculateMemoryPercent } from '../../../../lib/utils/container-stats.utils';
+import type { ReconnectingWebSocket } from '../../../../lib/utils/ws';
+
+export class ContainerStatsManager {
+ private connections = new Map<string, ReconnectingWebSocket<ContainerStats>>();
+ private stats = $state(new Map<string, ContainerStats>());
+ private loadingStates = $state(new Map<string, boolean>());
+
+ connect(containerId: string, envId: string): void {
+ if (this.connections.has(containerId)) return;
+
+ this.loadingStates = new Map(this.loadingStates).set(containerId, true);
+
+ const ws = createContainerStatsWebSocket({
+ getEnvId: () => envId,
+ containerId,
+ onMessage: (data: ContainerStats) => {
+ this.stats = new Map(this.stats).set(containerId, data);
+ this.loadingStates = new Map(this.loadingStates).set(containerId, false);
+ },
+ onError: (err) => {
+ console.error(`[ContainerStatsManager] Stats error for container ${containerId}:`, err);
+ this.loadingStates = new Map(this.loadingStates).set(containerId, false);
+ },
+ shouldReconnect: () => this.connections.has(containerId)
+ });
+
+ ws.connect();
+ this.connections.set(containerId, ws);
+ }
+
+ disconnect(containerId: string): void {
+ const ws = this.connections.get(containerId);
+ if (ws) {
+ ws.close();
+ this.connections.delete(containerId);
+ const newStats = new Map(this.stats);
+ newStats.delete(containerId);
+ this.stats = newStats;
+ const newLoadingStates = new Map(this.loadingStates);
+ newLoadingStates.delete(containerId);
+ this.loadingStates = newLoadingStates;
+ }
+ }
+
+ getCPUPercent(containerId: string): number | undefined {
+ const stats = this.stats.get(containerId);
+ if (!stats) return undefined;
+ return calculateCPUPercent(stats);
+ }
+
+ getMemoryPercent(containerId: string): number | undefined {
+ const stats = this.stats.get(containerId);
+ if (!stats) return undefined;
+ return calculateMemoryPercent(stats);
+ }
+
+ getMemoryUsage(containerId: string): { usage: number; limit: number } | undefined {
+ const stats = this.stats.get(containerId);
+ if (!stats) return undefined;
+ return {
+ usage: stats.memory_stats?.usage || 0,
+ limit: stats.memory_stats?.limit || 0
+ };
+ }
+
+ isLoading(containerId: string): boolean {
+ return this.loadingStates.get(containerId) ?? false;
+ }
+
+ hasConnection(containerId: string): boolean {
+ return this.connections.has(containerId);
+ }
+
+ getConnectedIds(): string[] {
+ return Array.from(this.connections.keys());
+ }
+
+ destroy(): void {
+ for (const ws of this.connections.values()) {
+ ws.close();
+ }
+ this.connections.clear();
+ this.stats = new Map();
+ this.loadingStates = new Map();
+ }
+}
diff --git a/frontend/src/routes/(app)/containers/container-table.svelte b/frontend/src/routes/(app)/containers/container-table.svelte
index d980eabb7..c893c3d0d 100644
--- a/frontend/src/routes/(app)/containers/container-table.svelte
+++ b/frontend/src/routes/(app)/containers/container-table.svelte
@@ -27,6 +27,9 @@
import ImageUpdateItem from '$lib/components/image-update-item.svelte';
import { PersistedState } from 'runed';
import { onMount } from 'svelte';
+ import { ContainerStatsManager } from './components/container-stats-manager.svelte';
+ import ContainerStatsCell from './components/container-stats-cell.svelte';
+ import { environmentStore } from '$lib/stores/environment.store.svelte';
import {
StartIcon,
StopIcon,
@@ -60,6 +63,8 @@
type ActionStatus = 'starting' | 'stopping' | 'restarting' | 'updating' | 'removing' | '';
let actionStatus = $state<Record<string, ActionStatus>>({});
+ let statsManager = $state<ContainerStatsManager | null>(null);
+
// Parse image reference into repo and tag
function parseImageRef(imageRef: string): { repo: string; tag: string } {
// Handle images like "nginx:latest", "library/nginx:1.0", "ghcr.io/org/image:tag"
@@ -235,9 +240,75 @@
let customSettings = $state<Record<string, unknown>>({});
let collapsedGroupsState = $state<PersistedState<Record<string, boolean>> | null>(null);
let collapsedGroups = $derived(collapsedGroupsState?.current ?? {});
+ let columnVisibility = $state<Record<string, boolean>>({});
onMount(() => {
collapsedGroupsState = new PersistedState<Record<string, boolean>>('container-groups-collapsed', {});
+
+ statsManager = new ContainerStatsManager();
+
+ // Check if stats columns are visible
+ const areStatsColumnsVisible = () => {
+ const cpuVisible = columnVisibility.cpuUsage !== false;
+ const memoryVisible = columnVisibility.memoryUsage !== false;
+ return cpuVisible || memoryVisible;
+ };
+
+ // Function to sync connections with running containers
+ const syncConnections = () => {
+ if (!statsManager) return;
+
+ // Only connect if stats columns are visible
+ if (!areStatsColumnsVisible()) {
+ // Disconnect all if columns are hidden
+ const connectedIds = statsManager.getConnectedIds();
+ for (const id of connectedIds) {
+ statsManager.disconnect(id);
+ }
+ return;
+ }
+
+ const runningContainers = containers.data?.filter((c) => c.state === 'running') ?? [];
+ const runningIds = new Set(runningContainers.map((c) => c.id));
+
+ const envId = environmentStore.selected?.id || '0';
+
+ // Connect new running containers
+ for (const container of runningContainers) {
+ if (!statsManager.hasConnection(container.id)) {
+ statsManager.connect(container.id, envId);
+ }
+ }
+
+ // Disconnect stopped containers
+ const connectedIds = statsManager.getConnectedIds();
+ for (const id of connectedIds) {
+ if (!runningIds.has(id)) {
+ statsManager.disconnect(id);
+ }
+ }
+ };
+
+ // Sync connections when containers or column visibility changes
+ const unsubscribe = $effect.root(() => {
+ $effect(() => {
+ // Track containers.data changes
+ containers.data;
+ // Track environment changes
+ environmentStore.selected?.id;
+ // Track column visibility changes
+ columnVisibility;
+
+ syncConnections();
+ });
+
+ return () => {};
+ });
+
+ return () => {
+ unsubscribe();
+ statsManager?.destroy();
+ };
});
let groupByProject = $derived.by(() => {
@@ -271,6 +342,20 @@
{ accessorKey: 'names', id: 'name', title: m.common_name(), sortable: !groupByProject, cell: NameCell },
{ accessorKey: 'state', title: m.common_state(), sortable: !groupByProject, cell: StateCell },
{ accessorKey: 'image', title: m.common_image(), sortable: !groupByProject, cell: ImageCell },
+ {
+ accessorFn: (row) => statsManager?.getCPUPercent(row.id) ?? -1,
+ id: 'cpuUsage',
+ title: m.containers_cpu_usage(),
+ sortable: false,
+ cell: CPUCell
+ },
+ {
+ accessorFn: (row) => statsManager?.getMemoryPercent(row.id) ?? -1,
+ id: 'memoryUsage',
+ title: m.containers_memory_usage(),
+ sortable: false,
+ cell: MemoryCell
+ },
{ accessorKey: 'status', title: m.common_status() },
{ accessorKey: 'imageId', id: 'update', title: m.containers_update_column(), cell: UpdateCell },
{ accessorKey: 'networkSettings', id: 'ipAddress', title: m.containers_ip_address(), sortable: false, cell: IPAddressCell },
@@ -281,6 +366,8 @@
const mobileFields = [
{ id: 'id', label: m.common_id(), defaultVisible: false },
{ id: 'state', label: m.common_state(), defaultVisible: true },
+ { id: 'cpuUsage', label: m.containers_cpu_usage(), defaultVisible: false },
+ { id: 'memoryUsage', label: m.containers_memory_usage(), defaultVisible: false },
{ id: 'status', label: m.common_status(), defaultVisible: true },
{ id: 'image', label: m.common_image(), defaultVisible: true },
{ id: 'ipAddress', label: m.containers_ip_address(), defaultVisible: false },
@@ -321,6 +408,20 @@
<span class="font-mono text-sm">{ip ?? m.common_na()}</span>
{/snippet}
+{#snippet CPUCell({ item }: { item: ContainerSummaryDto })}
+ <ContainerStatsCell
+ value={statsManager?.getCPUPercent(item.id)}
+ loading={statsManager?.isLoading(item.id) ?? false}
+ stopped={item.state !== 'running'}
+ type="cpu"
+ />
+{/snippet}
+
+{#snippet MemoryCell({ item }: { item: ContainerSummaryDto })}
+ {@const memoryData = statsManager?.getMemoryUsage(item.id)}
+ <ContainerStatsCell value={memoryData?.usage} limit={memoryData?.limit} stopped={item.state !== 'running'} type="memory" />
+{/snippet}
+
{#snippet PortsCell({ item }: { item: ContainerSummaryDto })}
<PortBadge ports={item.ports ?? []} />
{/snippet}
@@ -395,7 +496,7 @@
{#snippet ImageCell({ item }: { item: ContainerSummaryDto })}
<ArcaneTooltip.Root>
<ArcaneTooltip.Trigger>
- <span class="block max-w-[200px] cursor-default truncate text-left lg:max-w-[300px]">
+ <span class="block w-full cursor-default truncate text-left">
{item.image}
</span>
</ArcaneTooltip.Trigger>
@@ -602,6 +703,7 @@
bind:selectedIds
bind:mobileFieldVisibility
bind:customSettings
+ bind:columnVisibility
onRefresh={async (options) => (containers = await containerService.getContainers(options))}
{columns}
{mobileFields}
diff --git a/go.work.sum b/go.work.sum
index e07dc5984..8e54c256c 100644
--- a/go.work.sum
+++ b/go.work.sum
@@ -129,6 +129,7 @@ github.com/aws/smithy-go v1.22.5 h1:P9ATCXPMb2mPjYBgueqJNCA5S9UfktsW0tTxi+a7eqw=
github.com/aws/smithy-go v1.22.5/go.mod h1:t1ufH5HMublsJYulve2RKmHDC15xu1f26kHCp/HgceI=
github.com/bitly/go-hostpool v0.1.0 h1:XKmsF6k5el6xHG3WPJ8U0Ku/ye7njX7W81Ng7O2ioR0=
github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkNEM+Y=
+github.com/bits-and-blooms/bitset v1.24.3 h1:Bte86SlO3lwPQqww+7BE9ZuUCKIjfqnG5jtEyqA9y9Y=
github.com/bits-and-blooms/bitset v1.24.3/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
@@ -175,6 +176,7 @@ github.com/containernetworking/cni v1.3.0 h1:v6EpN8RznAZj9765HhXQrtXgX+ECGebEYEm
github.com/containernetworking/cni v1.3.0/go.mod h1:Bs8glZjjFfGPHMw6hQu82RUgEPNGEaBb9KS5KtNMnJ4=
github.com/containernetworking/plugins v1.8.0 h1:WjGbV/0UQyo8A4qBsAh6GaDAtu1hevxVxsEuqtBqUFk=
github.com/containernetworking/plugins v1.8.0/go.mod h1:JG3BxoJifxxHBhG3hFyxyhid7JgRVBu/wtooGEvWf1c=
+github.com/containernetworking/plugins v1.9.0 h1:Mg3SXBdRGkdXyFC4lcwr6u2ZB2SDeL6LC3U+QrEANuQ=
github.com/containernetworking/plugins v1.9.0/go.mod h1:JG3BxoJifxxHBhG3hFyxyhid7JgRVBu/wtooGEvWf1c=
github.com/containers/libtrust v0.0.0-20230121012942-c1716e8a8d01 h1:Qzk5C6cYglewc+UyGf6lc8Mj2UaPTHy/iF2De0/77CA=
github.com/containers/libtrust v0.0.0-20230121012942-c1716e8a8d01/go.mod h1:9rfv8iPl1ZP7aqh9YA68wnZv2NUDbXdcdPHVz0pFbPY=
@@ -332,6 +334,7 @@ github.com/jackc/pgx/v4 v4.18.2 h1:xVpYkNR5pk5bMCZGfClbO962UIqVABcAGt7ha1s/FeU=
github.com/jackc/pgx/v4 v4.18.2/go.mod h1:Ey4Oru5tH5sB6tV7hDmfWFahwF15Eb7DNXlRKx2CkVw=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
+github.com/jordanlewis/gcassert v0.0.0-20250430164644-389ef753e22e h1:a+PGEeXb+exwBS3NboqXHyxarD9kaboBbrSp+7GuBuc=
github.com/jordanlewis/gcassert v0.0.0-20250430164644-389ef753e22e/go.mod h1:ZybsQk6DWyN5t7An1MuPm1gtSZ1xDaTXS9ZjIOxvQrk=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
@@ -423,6 +426,7 @@ github.com/onsi/gomega v1.15.0 h1:WjP/FQ/sk43MRmnEcT+MlDw2TFvkrXlprrPST/IudjU=
github.com/onsi/gomega v1.15.0/go.mod h1:cIuvLEne0aoVhAgh/O6ac0Op8WWw9H6eYCriF+tEHG0=
github.com/opencontainers/runtime-tools v0.9.1-0.20250523060157-0ea5ed0382a2 h1:2xZEHOdeQBV6PW8ZtimN863bIOl7OCW/X10K0cnxKeA=
github.com/opencontainers/runtime-tools v0.9.1-0.20250523060157-0ea5ed0382a2/go.mod h1:MXdPzqAA8pHC58USHqNCSjyLnRQ6D+NjbpP+02Z1U/0=
+github.com/opencontainers/runtime-tools v0.9.1-0.20251114084447-edf4cb3d2116 h1:tAKu3NkKWZYpqBSOJKwTxT1wIGueiF7gcmcNgr5pNTY=
github.com/opencontainers/runtime-tools v0.9.1-0.20251114084447-edf4cb3d2116/go.mod h1:DKDEfzxvRkoQ6n9TGhxQgg2IM1lY4aM0eaQP4e3oElw=
github.com/otiai10/copy v1.14.1 h1:5/7E6qsUMBaH5AnQ0sSLzzTg1oTECmcCmT6lvF45Na8=
github.com/otiai10/copy v1.14.1/go.mod h1:oQwrEDDOci3IM8dJF0d8+jnbfPDllW6vUjNc3DoZm9I=
@@ -528,6 +532,7 @@ github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGC
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
+github.com/yuin/goldmark v1.2.1 h1:ruQGxdhGHe7FWOJPT0mKs5+pD2Xs1Bm/kdGlHO04FmM=
github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/zclconf/go-cty v1.17.0 h1:seZvECve6XX4tmnvRzWtJNHdscMtYEx5R7bnnVyd/d0=
@@ -654,4 +659,5 @@ sigs.k8s.io/yaml v1.6.0 h1:G8fkbMSAFqgEFgh4b1wmtzDnioxFCUgTZhlbj5P9QYs=
sigs.k8s.io/yaml v1.6.0/go.mod h1:796bPqUfzR/0jLAl6XjHl3Ck7MiyVv8dbTdyT3/pMf4=
tags.cncf.io/container-device-interface/specs-go v1.0.0 h1:8gLw29hH1ZQP9K1YtAzpvkHCjjyIxHZYzBAvlQ+0vD8=
tags.cncf.io/container-device-interface/specs-go v1.0.0/go.mod h1:u86hoFWqnh3hWz3esofRFKbI261bUlvUfLKGrDhJkgQ=
+tags.cncf.io/container-device-interface/specs-go v1.1.0 h1:QRZVeAceQM+zTZe12eyfuJuuzp524EKYwhmvLd+h+yQ=
tags.cncf.io/container-device-interface/specs-go v1.1.0/go.mod h1:u86hoFWqnh3hWz3esofRFKbI261bUlvUfLKGrDhJkgQ=