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.
22 lines
602 B
TypeScript
22 lines
602 B
TypeScript
import type { Config, Widget } from "./schema";
|
|
|
|
export interface WidgetInstance {
|
|
id: string;
|
|
groupName: string;
|
|
widget: Widget;
|
|
}
|
|
|
|
export function widgetId(groupIndex: number, widgetIndex: number): string {
|
|
return `${groupIndex}:${widgetIndex}`;
|
|
}
|
|
|
|
export function flattenWidgets(config: Config): WidgetInstance[] {
|
|
const instances: WidgetInstance[] = [];
|
|
config.groups.forEach((group, groupIndex) => {
|
|
group.widgets.forEach((widget, widgetIndex) => {
|
|
instances.push({ id: widgetId(groupIndex, widgetIndex), groupName: group.name, widget });
|
|
});
|
|
});
|
|
return instances;
|
|
}
|