Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,632 changes: 5 additions & 1,627 deletions runtime/host/dashboard.html

Large diffs are not rendered by default.

2,468 changes: 90 additions & 2,378 deletions runtime/host/dashboard.py

Large diffs are not rendered by default.

373 changes: 373 additions & 0 deletions runtime/host/dashboard_assets/app.js

Large diffs are not rendered by default.

270 changes: 270 additions & 0 deletions runtime/host/dashboard_assets/cards.js

Large diffs are not rendered by default.

167 changes: 167 additions & 0 deletions runtime/host/dashboard_assets/charts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
// Each plot owns a persistent SVG; geometry is computed only for a changed snapshot/window.
function chart(history, idx, now, cls, scale, window = "auto", limit = 10800) {
const span = window === "auto" ? limit : Math.min(Number(window), limit);
const start = Math.max(now - span, history[0]?.[0] ?? now - 1);
const width = Math.max(1, now - start), W = 300, H = 80;
const visible = history.filter(h => h[0] >= start && h[0] <= now);
const pts = visible.filter(h => has(h[idx]));
const peak = Math.max(0, ...pts.map(h => h[idx]));
const magnitude = 10 ** Math.floor(Math.log10(Math.max(1, peak * 1.1)));
const top = scale || Math.ceil(Math.max(2, peak * 1.1) / magnitude) * magnitude;
let d = "", prev = null;
for (const h of visible) {
if (!has(h[idx])) { prev = null; continue; }
const x = (h[0] - start) / width * W, y = H - 2 - h[idx] / top * (H - 4);
d += (prev === null || h[0] - prev > 185 ? "M" : "L") + x.toFixed(1) + "," + y.toFixed(1);
prev = h[0];
}
return { d, peak, top, start, now, rows: pts,
svg: `<svg class="${cls}" viewBox="0 0 ${W} ${H}" preserveAspectRatio="none" aria-hidden="true"><path d="${d}" vector-effect="non-scaling-stroke"/></svg>` };
}

const graphNames = { 1: "Output tok/s", 4: "KV cache use", 5: "Prefill tok/s" };
const windows = [["auto", "Auto"], ["300", "5 min"], ["900", "15 min"], ["3600", "1 h"], ["10800", "3 h"]];
const views = new Map();
// One viewer-local window and pause time; each member retains its frozen samples.
const graphView = { window: "auto", paused: null };
try { graphView.window = localStorage.getItem("sparkring-window") || "auto"; } catch (_) { /* Storage is optional. */ }

if (!windows.some(w => w[0] === graphView.window)) graphView.window = "auto";
function viewFor(id) {
if (!views.has(id)) views.set(id, { history: graphView.paused === null ? null : [] });
return { ...graphView, history: views.get(id).history };
}
function updateGraphControls() {
const controls = $("page-graphs");
if (!controls.firstChild) patch(controls, `<span class="seg" role="group" aria-label="Graph window">${windows.map(([v, label]) =>
`<button type="button" data-window="${v}" aria-pressed="false">${label.replace(" min", "m").replace(" h", "h")}</button>`).join("")}</span>
<button type="button" class="pause" data-pause aria-label="Pause graphs">❚❚</button><span class="pause-age"></span>`);
for (const b of controls.querySelectorAll("[data-window]")) attr(b, "aria-pressed", String(b.dataset.window === graphView.window));
const pause = controls.querySelector("[data-pause]");
text(pause, graphView.paused === null ? "❚❚" : "▶");
attr(pause, "aria-label", graphView.paused === null ? "Pause graphs" : "Resume graphs");
}
function options(selected, dialog = false) {
return [...windows, ...(dialog ? [["21600", "6 h"]] : [])].map(([v, label]) =>
`<option value="${v}"${v === selected ? " selected" : ""}>${label}</option>`).join("");
}
function graphBox(s, idx) {
// The plot updater owns children of this island, including pointer state.
return `<button type="button" class="chart sparkline" data-graph="${idx}" data-graph-member="${esc(s.id)}" aria-label="Expand ${graphNames[idx]} for ${esc(s.name)}" aria-haspopup="dialog" data-island></button>`;
}
function charts(s) {
return `<div class="charts">${[1, 5, 4].map(i => graphBox(s, i)).join("")}</div>`;
}
function plotShell(idx, title = "") {
return `${title}<div class="plot-frame"><div class="axis y-axis"><span>0</span><span></span><span></span></div>
<svg class="${idx === 4 ? "c2" : "c1"}" viewBox="0 0 300 80" preserveAspectRatio="none" aria-hidden="true"><path d="" vector-effect="non-scaling-stroke"/></svg>
</div><div class="axis x-axis"><span></span><span></span></div><span class="empty-plot" hidden>no data yet</span>`;
}
function drawPlot(box, history, idx, now, window, limit) {
const signature = JSON.stringify([history, window]);
if (box.plotSignature === signature) return;
box.plotSignature = signature;
const g = chart(history, idx, now, "", idx === 4 ? 1 : null, window, limit);
box.plot = g;
attr(box.querySelector("path"), "d", g.rows.length ? g.d : "M0,78L300,78");
box.classList.toggle("empty", !g.rows.length);
setHidden(box.querySelector(".empty-plot"), !!g.rows.length);
const ys = box.querySelectorAll(".y-axis span"), xs = box.querySelectorAll(".x-axis span");
const fmt = idx === 4 ? pct : int;
text(ys[1], fmt(g.top / 2)); text(ys[2], fmt(g.top));
text(xs[0], now - g.start <= 900 ? dur(now - g.start) + " ago" : clock(g.start));
text(xs[1], now - g.start <= 900 ? "now" : clock(now));
if (has(box.pointerX)) inspectPointer(box, box.pointerX);
}
function updateGraphs(member) {
const card = [...$("stacks").children].find(c => c.dataset.member === member.id);
const v = viewFor(member.id), now = v.paused ?? serverNow(), history = v.history ?? member.history ?? [];
for (const box of card.querySelectorAll("[data-graph]")) {
const idx = Number(box.dataset.graph);
if (!box.firstChild) patch(box, plotShell(idx, `<span class="k">${graphNames[idx]}</span>`) + '<output></output>');
drawPlot(box, history, idx, now, v.window, 10800);
}
}
let graphSelection = null, graphOpener = null;
function exactGraphValue(row, idx) {
return row ? `${new Date(row[0] * 1000).toISOString().replace(/\.\d{3}Z$/, "Z")} \u00b7 ${graphNames[idx]}: ${idx === 4 ? pct(row[idx]) : rate(row[idx])} \u00b7 ${row[6] === "plugin" ? "plugin" : "approx /metrics"}` : "No sample here";
}
function inspectGraph() {
if (graphSelection) text($("graph-value"), exactGraphValue(graphSelection.rows[Number($("graph-sample").value)], graphSelection.idx));
}
function drawDialog() {
const g = graphSelection, box = $("graph-body");
const selectedAt = g.rows?.[Number($("graph-sample").value)]?.[0];
if (!box.firstChild) patch(box, plotShell(g.idx));
attr(box.querySelector("svg"), "class", g.idx === 4 ? "c2" : "c1");
box.plotSignature = null;
drawPlot(box, g.history, g.idx, g.now, $("graph-window").value, 21600);
g.rows = box.plot.rows;
$("graph-sample").max = Math.max(0, g.rows.length - 1);
const selected = g.rows.findIndex(r => r[0] === selectedAt);
$("graph-sample").value = selected < 0 ? Math.max(0, g.rows.length - 1) : selected;
$("graph-sample").disabled = !g.rows.length;
inspectGraph();
}
function openGraph(box, opener) {
const id = box.dataset.graphMember, idx = Number(box.dataset.graph), v = viewFor(id);
const member = data.groups.flatMap(g => g.members || []).find(m => m.id === id);
graphSelection = { id, idx, history: (v.history ?? member.history ?? []).map(r => [...r]), now: v.paused ?? serverNow() };
$("graph-dialog").style.setProperty("--gc", memberColor(member));
graphOpener = opener;
text($("graph-title"), graphNames[idx] + " — frozen snapshot");
patch($("graph-window"), options(v.window, true));
$("graph-window").value = v.window;
drawDialog(); $("graph-dialog").showModal();
}
function pointerSample(clientX, box) {
const rect = box.querySelector("svg").getBoundingClientRect(), g = box.plot;
const target = g.start + Math.max(0, Math.min(1, (clientX - rect.left) / rect.width)) * (g.now - g.start);
const row = g.rows.reduce((best, r) => !best || Math.abs(r[0] - target) < Math.abs(best[0] - target) ? r : best, null);
return row && Math.abs(row[0] - target) <= 185 ? row : null;
}
function inspectPointer(box, clientX) {
box.pointerX = clientX;
text(box.querySelector("output"), exactGraphValue(pointerSample(clientX, box), Number(box.dataset.graph)));
}

function initChartEvents() {
$("graph-window").addEventListener("change", drawDialog);
$("graph-close").addEventListener("click", () => $("graph-dialog").close());
$("graph-dialog").addEventListener("close", () => { graphSelection = null; graphOpener?.focus(); });
$("graph-sample").addEventListener("input", inspectGraph);
$("stacks").addEventListener("pointermove", event => {
const box = event.target.closest("[data-graph]");
if (box && event.target.closest("svg")) inspectPointer(box, event.clientX);
});
$("stacks").addEventListener("pointerout", event => {
const box = event.target.closest("[data-graph]");
if (box && !box.querySelector("svg").contains(event.relatedTarget)) box.pointerX = null;
});
$("page-graphs").addEventListener("click", event => {
const choice = event.target.closest("[data-window]");
if (choice) {
graphView.window = choice.dataset.window;
try { localStorage.setItem("sparkring-window", graphView.window); } catch (_) { /* Storage is optional. */ }
scheduleRender();
return;
}
if (!event.target.closest("[data-pause]") || !data) return;
graphView.paused = graphView.paused === null ? serverNow() : null;
for (const member of data.groups.flatMap(g => g.members || [])) {
views.set(member.id, { history: graphView.paused === null ? null : (member.history || []).map(r => [...r]) });
}
for (const box of document.querySelectorAll("[data-graph]")) box.plotSignature = null;
scheduleRender();
});
$("stacks").addEventListener("click", event => {
const box = event.target.closest("[data-graph]");
if (box) openGraph(box, box);
});
$("graph-body").addEventListener("pointermove", event => {
if (!event.target.closest("svg") || !graphSelection) return;
const row = pointerSample(event.clientX, $("graph-body"));
if (!row) { text($("graph-value"), "No sample here"); return; }
$("graph-sample").value = graphSelection.rows.indexOf(row); inspectGraph();
});
}
Loading
Loading