Files
pulsenode/components/widgets/docker/Widget.tsx
T
valknar 9890f964c5 feat: live docker/database widgets over WebSocket (M2)
Adds a custom server.ts (http server + Next request handler + a
noServer:true WebSocket server on /ws) so the app can push live data
without polling. A CollectorScheduler runs one interval-based job per
docker/database widget instance, backed by dockerode against
/var/run/docker.sock, and reconciles jobs when config.yml changes.

Config hot-reload is now fully wired: chokidar watches config.yml/.env,
re-validates on change, and broadcasts config:update (or a
non-destructive config:error, keeping the last-good config) to every
connected browser. The client subscribes to per-widget topics over a
single shared WebSocket with exponential-backoff reconnect and
last-result caching for instant resubscribe.

Verified end-to-end against real throwaway containers (nginx, redis):
live CPU/mem/uptime/health streamed over the socket, interval changes
picked up without a server restart, and a broken config.yml correctly
falls back to the last-valid config instead of crashing the app.
2026-08-17 14:01:53 +02:00

49 lines
1.9 KiB
TypeScript

"use client";
import type { Widget } from "@/lib/config/schema";
import { useWidgetSubscription } from "@/lib/ws/client";
import { StatusDot } from "@/components/widgets/StatusDot";
import { formatBytes, formatUptime } from "@/lib/format";
type DockerWidget = Extract<Widget, { type: "docker" }>;
export function DockerWidget({ widget, widgetId }: { widget: DockerWidget; widgetId: string }) {
const result = useWidgetSubscription(widgetId);
const data = result?.type === "docker" ? result.data : null;
const errorMessage = result?.type === "error" ? result.message : null;
return (
<div className="flex flex-col gap-2 rounded-[var(--radius-widget)] border border-border bg-surface p-4">
<div className="flex items-center justify-between gap-2">
{widget.href ? (
<a
href={widget.href}
target="_blank"
rel="noreferrer"
className="text-sm font-medium text-fg hover:text-accent"
>
{widget.name}
</a>
) : (
<span className="text-sm font-medium text-fg">{widget.name}</span>
)}
<StatusDot status={data?.status} health={data?.health} />
</div>
{errorMessage && <span className="text-xs text-status-down">{errorMessage}</span>}
{data && (
<dl className="flex flex-col gap-1 text-xs text-fg-muted">
{data.uptimeSeconds !== null && <div>Uptime: {formatUptime(data.uptimeSeconds)}</div>}
{widget.showStats && data.cpuPercent !== null && <div>CPU: {data.cpuPercent.toFixed(1)}%</div>}
{widget.showStats && data.memUsageBytes !== null && (
<div>
Mem: {formatBytes(data.memUsageBytes)}
{data.memLimitBytes ? ` / ${formatBytes(data.memLimitBytes)}` : ""}
</div>
)}
{data.restartCount > 0 && <div>Restarts: {data.restartCount}</div>}
</dl>
)}
</div>
);
}