Skip to content

Commit 9903e40

Browse files
authored
feat(ui): add live CPU/memory/delay sparkline graphs to the system busyness overlay (#127650)
* feat(ui): add cpu/memory graphs to system busyness overlay * refactor(ui): redesign busyness overlay vitals as sparkline stat tiles Merge the duplicated sparkline row and numeric tile grid into three vital tiles (CPU, memory, event-loop delay) with gradient area charts, a live pulse dot, pointer scrubbing with value+age readout, and a danger tint driven by the gateway's own event-loop degradation reasons. Memory auto-ranges its baseline so RSS trends stay visible.
1 parent 75b736c commit 9903e40

12 files changed

Lines changed: 541 additions & 61 deletions

File tree

‎docs/web/control-ui.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ select it to open the owning Approvals page.
331331

332332
</Accordion>
333333
<Accordion title="Debug, logs, update">
334-
- Debug: status/health/models snapshots, event log, and manual RPC calls (`status`, `health`, `models.list`).
334+
- Debug: status/health/models snapshots, event log, manual RPC calls, and a System busyness overlay with live CPU, memory, and event-loop delay graphs (`status`, `health`, `models.list`).
335335
- The event log includes Control UI refresh/RPC timings, slow chat/config render timings, and browser responsiveness entries for long animation frames or long tasks when the browser exposes those PerformanceObserver entry types.
336336
- Logs: live tail of gateway file logs with filter/export (`logs.tail`).
337337
- Update: run a package/git update plus restart (`update.run`) with a restart report, then poll `update.status` after reconnect to verify the running gateway version.

‎scripts/control-ui-mock-dev.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2623,7 +2623,12 @@ async function createChatPickerScenario(
26232623
},
26242624
},
26252625
status: {
2626-
eventLoop: { utilization: 0.42, delayP99Ms: 12, delayMaxMs: 87 },
2626+
eventLoop: { utilization: 0.42, cpuCoreRatio: 0.24, delayP99Ms: 12, delayMaxMs: 87 },
2627+
processMemory: {
2628+
rssBytes: 432 * 1_048_576,
2629+
heapUsedBytes: 210 * 1_048_576,
2630+
heapTotalBytes: 280 * 1_048_576,
2631+
},
26272632
uptimeMs: 5_412_000,
26282633
},
26292634
"last-heartbeat": { ts: baseTime },

‎src/gateway/server-methods/health.owner-routing.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ describe("Gateway status owner routing", () => {
4040

4141
expect(respond).toHaveBeenCalledTimes(1);
4242
expect(respond.mock.calls[0]?.[0]).toBe(true);
43+
expect(respond.mock.calls[0]?.[1]).toEqual(
44+
expect.objectContaining({
45+
processMemory: {
46+
rssBytes: expect.any(Number),
47+
heapUsedBytes: expect.any(Number),
48+
heapTotalBytes: expect.any(Number),
49+
},
50+
}),
51+
);
4352
expect(respond.mock.calls[0]?.[2]).toBeUndefined();
4453
expect(resolveRequestedSessionAgentId(config, "main")).toMatchObject({ ok: false });
4554
expect(resolveRequestedSessionAgentId(config, "agent:molty:main")).toEqual({

‎src/gateway/server-methods/health.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ export const healthHandlers: GatewayRequestHandlers = {
184184
if (context.getEventLoopHealth) {
185185
status.eventLoop = context.getEventLoopHealth();
186186
}
187+
const memory = process.memoryUsage();
188+
status.processMemory = {
189+
rssBytes: memory.rss,
190+
heapUsedBytes: memory.heapUsed,
191+
heapTotalBytes: memory.heapTotal,
192+
};
187193
respond(true, status, undefined);
188194
},
189195
};

‎src/gateway/server-methods/server-methods.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4375,7 +4375,7 @@ describe("gateway healthHandlers.status scope handling", () => {
43754375
includeSensitive,
43764376
includeChannelSummary: true,
43774377
});
4378-
expect(respond).toHaveBeenCalledWith(true, { ok: true }, undefined);
4378+
expect(respond).toHaveBeenCalledWith(true, expect.objectContaining({ ok: true }), undefined);
43794379
},
43804380
);
43814381

@@ -4398,7 +4398,7 @@ describe("gateway healthHandlers.status scope handling", () => {
43984398
includeSensitive: false,
43994399
includeChannelSummary: false,
44004400
});
4401-
expect(respond).toHaveBeenCalledWith(true, { ok: true }, undefined);
4401+
expect(respond).toHaveBeenCalledWith(true, expect.objectContaining({ ok: true }), undefined);
44024402
});
44034403
});
44044404

‎src/status/types.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ export type StatusSummary = {
5656
runtimeVersion?: string | null;
5757
hostDesktop?: import("../gateway/desktop/host-source.js").HostDesktopStatus;
5858
eventLoop?: import("../gateway/server/event-loop-health.js").GatewayEventLoopHealth;
59+
processMemory?: {
60+
rssBytes: number;
61+
heapUsedBytes: number;
62+
heapTotalBytes: number;
63+
};
5964
linkChannel?: {
6065
id: ChannelId;
6166
label: string;

‎ui/src/i18n/locales/en.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,9 +1439,13 @@ export const en: TranslationMap = {
14391439
status: "Event loop / status",
14401440
activeRuns: "Active runs",
14411441
events: "Events",
1442-
utilization: "Utilization",
1442+
cpu: "CPU",
1443+
memory: "Memory",
1444+
memoryMb: "{value} MB",
1445+
loopShort: "loop {value}",
1446+
heapShort: "heap {value}",
1447+
maxShort: "max {value}",
14431448
delayP99: "Delay p99",
1444-
delayMax: "Delay max",
14451449
uptime: "Uptime",
14461450
activeRunsCount: "{count} active",
14471451
noActiveRuns: "No active runs.",

‎ui/src/pages/debug/debug-overlay-sections.ts‎

Lines changed: 102 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
2-
import { html, type TemplateResult } from "lit";
2+
import { html, nothing, type TemplateResult } from "lit";
33
import type { GatewayBrowserClient } from "../../api/gateway.ts";
44
import type { ApplicationGateway } from "../../app/gateway.ts";
55
import { t } from "../../i18n/index.ts";
@@ -13,6 +13,8 @@ import {
1313
type CommandLaneDiagnostics,
1414
} from "../../lib/gateway-diagnostics.ts";
1515
import { renderCommandLaneRows } from "./lane-table.ts";
16+
import "./sparkline-tile.ts";
17+
import type { SparklineSample } from "./sparkline-tile.ts";
1618

1719
type DebugOverlaySectionContext = {
1820
client: GatewayBrowserClient;
@@ -23,7 +25,7 @@ type TypedDebugOverlaySectionDescriptor<T> = {
2325
id: string;
2426
titleKey: string;
2527
load: (context: DebugOverlaySectionContext, signal: AbortSignal) => Promise<T>;
26-
render: (value: T) => TemplateResult;
28+
render: (value: T, statusHistory: readonly DebugOverlayStatusSample[]) => TemplateResult;
2729
};
2830

2931
export type DebugOverlaySectionDescriptor = TypedDebugOverlaySectionDescriptor<unknown>;
@@ -33,24 +35,36 @@ function defineDebugOverlaySection<T>(
3335
): DebugOverlaySectionDescriptor {
3436
return {
3537
...descriptor,
36-
render: (value) => {
38+
render: (value, statusHistory) => {
3739
// SAFETY: This closure keeps each descriptor's load result paired with its own renderer.
38-
return descriptor.render(value as T);
40+
return descriptor.render(value as T, statusHistory);
3941
},
4042
};
4143
}
4244

4345
type EventLoopSnapshot = {
4446
utilization?: number;
47+
cpuCoreRatio?: number;
4548
delayP99Ms?: number;
4649
delayMaxMs?: number;
50+
reasons?: string[];
4751
};
4852

49-
type StatusSectionValue = {
53+
export type DebugOverlayStatusSnapshot = {
5054
eventLoop?: EventLoopSnapshot;
55+
processMemory?: {
56+
rssBytes: number;
57+
heapUsedBytes: number;
58+
heapTotalBytes: number;
59+
};
5160
uptimeMs?: number;
5261
};
5362

63+
export type DebugOverlayStatusSample = {
64+
at: number;
65+
status: DebugOverlayStatusSnapshot;
66+
};
67+
5468
type ActiveSession = {
5569
key?: string;
5670
sessionId?: string;
@@ -76,41 +90,86 @@ function renderLanes(diagnostics: CommandLaneDiagnostics): TemplateResult {
7690
`;
7791
}
7892

79-
function renderStatus(status: StatusSectionValue): TemplateResult {
93+
function collectSamples(
94+
history: readonly DebugOverlayStatusSample[],
95+
read: (status: DebugOverlayStatusSnapshot) => number | undefined,
96+
): SparklineSample[] {
97+
const samples: SparklineSample[] = [];
98+
for (const entry of history) {
99+
const value = read(entry.status);
100+
if (typeof value === "number" && Number.isFinite(value)) {
101+
samples.push({ value, at: entry.at });
102+
}
103+
}
104+
return samples;
105+
}
106+
107+
function formatPercent(value: number): string {
108+
return `${Math.round(value * 100)}%`;
109+
}
110+
111+
function formatMegabytes(bytes: number): string {
112+
return t("debug.overlay.memoryMb", { value: String(Math.round(bytes / 1_048_576)) });
113+
}
114+
115+
function formatDelayMs(value: number): string {
116+
return formatDurationCompact(value) ?? t("common.na");
117+
}
118+
119+
function renderStatus(
120+
status: DebugOverlayStatusSnapshot,
121+
history: readonly DebugOverlayStatusSample[],
122+
): TemplateResult {
80123
const eventLoop = status.eventLoop;
81-
const utilization =
124+
const reasons = eventLoop?.reasons ?? [];
125+
const cpuDegraded = reasons.includes("cpu") || reasons.includes("event_loop_utilization");
126+
const delayDegraded = reasons.includes("event_loop_delay");
127+
const loopSub =
82128
typeof eventLoop?.utilization === "number"
83-
? `${Math.round(eventLoop.utilization * 100)}%`
84-
: t("common.na");
85-
const delay =
86-
typeof eventLoop?.delayP99Ms === "number"
87-
? formatDurationCompact(eventLoop.delayP99Ms)
88-
: t("common.na");
89-
const maxDelay =
129+
? t("debug.overlay.loopShort", { value: formatPercent(eventLoop.utilization) })
130+
: "";
131+
const heapSub =
132+
typeof status.processMemory?.heapUsedBytes === "number"
133+
? t("debug.overlay.heapShort", { value: formatMegabytes(status.processMemory.heapUsedBytes) })
134+
: "";
135+
const maxSub =
90136
typeof eventLoop?.delayMaxMs === "number"
91-
? formatDurationCompact(eventLoop.delayMaxMs)
92-
: t("common.na");
137+
? t("debug.overlay.maxShort", { value: formatDelayMs(eventLoop.delayMaxMs) })
138+
: "";
93139
return html`
94-
<dl class="debug-overlay__metrics">
95-
<div>
96-
<dt>${t("debug.overlay.utilization")}</dt>
97-
<dd class="mono">${utilization}</dd>
98-
</div>
99-
<div>
100-
<dt>${t("debug.overlay.delayP99")}</dt>
101-
<dd class="mono">${delay}</dd>
102-
</div>
103-
<div>
104-
<dt>${t("debug.overlay.delayMax")}</dt>
105-
<dd class="mono">${maxDelay}</dd>
106-
</div>
107-
${typeof status.uptimeMs === "number"
108-
? html`<div>
109-
<dt>${t("debug.overlay.uptime")}</dt>
110-
<dd class="mono">${formatDurationHuman(status.uptimeMs)}</dd>
111-
</div>`
112-
: ""}
113-
</dl>
140+
<div class="debug-overlay__vitals">
141+
<openclaw-debug-sparkline
142+
class="debug-overlay__vital debug-overlay__vital--cpu"
143+
data-degraded=${cpuDegraded ? "" : nothing}
144+
.label=${t("debug.overlay.cpu")}
145+
.sub=${loopSub}
146+
.samples=${collectSamples(history, (sample) => sample.eventLoop?.cpuCoreRatio)}
147+
.format=${formatPercent}
148+
.floorMax=${1}
149+
></openclaw-debug-sparkline>
150+
<openclaw-debug-sparkline
151+
class="debug-overlay__vital debug-overlay__vital--memory"
152+
.label=${t("debug.overlay.memory")}
153+
.sub=${heapSub}
154+
.samples=${collectSamples(history, (sample) => sample.processMemory?.rssBytes)}
155+
.format=${formatMegabytes}
156+
autorange
157+
></openclaw-debug-sparkline>
158+
<openclaw-debug-sparkline
159+
class="debug-overlay__vital debug-overlay__vital--delay"
160+
data-degraded=${delayDegraded ? "" : nothing}
161+
.label=${t("debug.overlay.delayP99")}
162+
.sub=${maxSub}
163+
.samples=${collectSamples(history, (sample) => sample.eventLoop?.delayP99Ms)}
164+
.format=${formatDelayMs}
165+
.floorMax=${20}
166+
></openclaw-debug-sparkline>
167+
</div>
168+
${typeof status.uptimeMs === "number"
169+
? html`<div class="debug-overlay__vitals-footer mono">
170+
${t("debug.overlay.uptime")} ${formatDurationHuman(status.uptimeMs)}
171+
</div>`
172+
: nothing}
114173
`;
115174
}
116175

@@ -156,11 +215,16 @@ export const DEBUG_OVERLAY_SECTIONS: readonly DebugOverlaySectionDescriptor[] =
156215
id: "status",
157216
titleKey: "debug.overlay.status",
158217
load: async (context, signal) => {
159-
const value = await context.client.request<StatusSectionValue>("status", {}, { signal });
218+
const value = await context.client.request<DebugOverlayStatusSnapshot>(
219+
"status",
220+
{},
221+
{ signal },
222+
);
160223
return {
161224
eventLoop: value.eventLoop,
225+
processMemory: value.processMemory,
162226
...(typeof value.uptimeMs === "number" ? { uptimeMs: value.uptimeMs } : {}),
163-
} satisfies StatusSectionValue;
227+
} satisfies DebugOverlayStatusSnapshot;
164228
},
165229
render: renderStatus,
166230
}),

‎ui/src/pages/debug/debug-overlay.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ import "../../styles/debug.css";
99
import {
1010
DEBUG_OVERLAY_SECTIONS,
1111
type DebugOverlaySectionDescriptor,
12+
type DebugOverlayStatusSample,
13+
type DebugOverlayStatusSnapshot,
1214
} from "./debug-overlay-sections.ts";
1315

1416
const DEBUG_OVERLAY_POLL_INTERVAL_MS = 2000;
17+
const DEBUG_OVERLAY_HISTORY_LIMIT = 90;
1518

1619
type SectionState =
1720
| { status: "loading" }
@@ -28,6 +31,7 @@ export class DebugOverlay extends OpenClawLightDomElement {
2831
private requestController: AbortController | null = null;
2932
private requestActive = false;
3033
private requestGeneration = 0;
34+
private statusHistory: DebugOverlayStatusSample[] = [];
3135
private eventLogSource: ApplicationContext["gateway"] | null = null;
3236
private unsubscribeEventLog: (() => void) | null = null;
3337
private readonly polling = new PollController(
@@ -54,6 +58,7 @@ export class DebugOverlay extends OpenClawLightDomElement {
5458
return;
5559
}
5660
this.open = true;
61+
this.statusHistory = [];
5762
document.addEventListener("keydown", this.handleKeydown, true);
5863
this.syncEventLogSubscription();
5964
this.sections = new Map(
@@ -134,6 +139,14 @@ export class DebugOverlay extends OpenClawLightDomElement {
134139
if (!this.open || generation !== this.requestGeneration) {
135140
return;
136141
}
142+
if (id === "status" && state.status === "ready") {
143+
// SAFETY: The status descriptor owns this section id and always returns a status snapshot.
144+
const snapshot = state.value as DebugOverlayStatusSnapshot;
145+
this.statusHistory = [
146+
...this.statusHistory.slice(-(DEBUG_OVERLAY_HISTORY_LIMIT - 1)),
147+
{ at: Date.now(), status: snapshot },
148+
];
149+
}
137150
const next = new Map(this.sections);
138151
next.set(id, state);
139152
this.sections = next;
@@ -148,7 +161,7 @@ export class DebugOverlay extends OpenClawLightDomElement {
148161
? html`<div class="debug-overlay__empty">${t("common.loading")}</div>`
149162
: state.status === "unavailable"
150163
? html`<div class="debug-overlay__empty">${t("debug.overlay.unavailable")}</div>`
151-
: section.render(state.value)}
164+
: section.render(state.value, this.statusHistory)}
152165
</section>
153166
`;
154167
}

0 commit comments

Comments
 (0)