Dashboard: KV cache on MLX, a completed-request table, honest GPU charts

Three gaps, all of them things the dashboard drew but never filled.

KV cache was never reported on MLX: /llmhost/metrics had no "kv" key at all,
so the tile and chart sat empty. mlx_lm has no endpoint for it, but it logs
"Prompt Cache: N sequences, X GB" (decimal GB, n_bytes/1e9) and that stream
already passes through _pump_output, so pick it out there and report a fraction
of --prompt-cache-bytes -- the same shape vLLM's kv already has, so the sampler
needs no backend special-casing. Peak is kept alongside the current value.

GPU temperature and power are root-only on macOS (powermetrics), so hw.live_stats
has always returned None for them on Apple. Two permanently blank charts is worse
than none: hide them and say why when the hardware doesn't report them.

Add a completed-request table above the server log: when each request finished,
its duration, time to first token, prompt and generated tokens, the rate for each
phase, and peak KV during the run. Rates are split at the first token -- prompt
tokens over TTFT, generated tokens over what's left -- since a single rate over
the whole duration blurs prefill into generation. The proxy keeps the last 50 runs;
peak KV is joined in by the sampler, which is the only side that samples KV on a
timer.

Also: close the upstream connection explicitly when a client hangs up mid-answer
rather than leaving it to GC, log that in one line, and collapse mlx_lm's
resulting BrokenPipeError traceback in the log view. Any other traceback is left
verbatim.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Neil Bantoc 2026-11-03 01:28:09 -08:00
parent 2c0818ca2b
commit 944eda06cc
3 changed files with 273 additions and 19 deletions

View file

@ -116,6 +116,20 @@ button.danger { color: var(--bad); }
}
.chart .axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--faint); margin-top: 4px; }
.runs { margin-top: 14px; }
.runs .head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.runs .head h2 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.runs .head .sub { color: var(--muted); font-size: 12px; }
.runs .scroll { overflow-x: auto; }
.runs table { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.runs th, .runs td { padding: 5px 10px 5px 0; text-align: right; white-space: nowrap; }
.runs th:first-child, .runs td:first-child { text-align: left; padding-left: 0; }
.runs th { color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border); font-size: 11.5px; }
.runs tbody tr + tr td { border-top: 1px solid color-mix(in srgb, var(--border) 55%, transparent); }
.runs td.none { color: var(--muted); }
.runs tr.aborted td:first-child::after { content: " cancelled"; color: var(--bad); font-size: 11px; }
.runs tfoot td { border-top: 1px solid var(--border); font-weight: 600; }
.runs .empty { color: var(--muted); font-size: 13px; padding: 6px 0 2px; }
details.logs { margin-top: 14px; }
details.logs summary { cursor: pointer; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; list-style: none; }
details.logs summary::before { content: "▸ "; }
@ -188,12 +202,32 @@ pre {
<div class="panel chart"><div class="head"><span>Time to first token</span><b id="c-ttft-v"></b></div><svg id="c-ttft" viewBox="0 0 300 90" preserveAspectRatio="none"></svg><div class="axis"><span>10 min ago</span><span>now</span></div></div>
<div class="panel chart"><div class="head"><span>KV cache %</span><b id="c-kv-v"></b></div><svg id="c-kv" viewBox="0 0 300 90" preserveAspectRatio="none"></svg><div class="axis"><span>10 min ago</span><span>now</span></div></div>
</div>
<div class="grid charts">
<div class="grid charts" id="gpu-charts">
<div class="panel chart"><div class="head"><span>GPU utilization %</span><b id="c-util-v"></b></div><svg id="c-util" viewBox="0 0 300 90" preserveAspectRatio="none"></svg><div class="axis"><span>10 min ago</span><span>now</span></div></div>
<div class="panel chart"><div class="head"><span>GPU temperature °C</span><b id="c-temp-v"></b></div><svg id="c-temp" viewBox="0 0 300 90" preserveAspectRatio="none"></svg><div class="axis"><span>10 min ago</span><span id="c-temp-max">0–100 °C</span><span>now</span></div></div>
<div class="panel chart"><div class="head"><span>GPU power W</span><b id="c-power-v"></b></div><svg id="c-power" viewBox="0 0 300 90" preserveAspectRatio="none"></svg><div class="axis"><span>10 min ago</span><span id="c-power-max"></span><span>now</span></div></div>
<div class="panel chart" id="p-temp"><div class="head"><span>GPU temperature °C</span><b id="c-temp-v"></b></div><svg id="c-temp" viewBox="0 0 300 90" preserveAspectRatio="none"></svg><div class="axis"><span>10 min ago</span><span id="c-temp-max">0–100 °C</span><span>now</span></div></div>
<div class="panel chart" id="p-power"><div class="head"><span>GPU power W</span><b id="c-power-v"></b></div><svg id="c-power" viewBox="0 0 300 90" preserveAspectRatio="none"></svg><div class="axis"><span>10 min ago</span><span id="c-power-max"></span><span>now</span></div></div>
<div class="panel chart" id="p-nogpu" hidden><div class="head"><span>GPU temperature &amp; power</span></div><div class="empty" id="nogpu-why">not available on this hardware</div></div>
</div>
<section class="panel runs" id="runs">
<div class="head">
<h2>Completed requests</h2>
<span class="sub" id="runs-sub"></span>
</div>
<div class="scroll">
<table>
<thead><tr>
<th>Finished</th><th>Duration</th><th>TTFT</th>
<th>Prompt</th><th>Prompt tok/s</th>
<th>Generated</th><th>Gen tok/s</th><th>Peak KV</th>
</tr></thead>
<tbody id="runs-body"></tbody>
<tfoot id="runs-foot"></tfoot>
</table>
</div>
<div class="empty" id="runs-empty" hidden>No requests finished yet.</div>
</section>
<details class="panel logs" id="logs">
<summary>Server log</summary>
<pre id="log-text">…</pre>
@ -339,6 +373,10 @@ function render(s) {
$("t-req-s").textContent = live ? `${fmt.n(m.waiting)} waiting` + (m.preemptions ? ` · ${fmt.n(m.preemptions)} preempted` : "") : "";
setV("t-kv", live ? fmt.n(m.kv_pct, 1) : "—", "%");
$("b-kv").style.width = (live && m.kv_pct != null ? m.kv_pct : 0) + "%";
if (m.kv_bytes != null && m.kv_budget_bytes) {
$("t-kv").title = `${(m.kv_bytes / 1e9).toFixed(2)} GB of ${(m.kv_budget_bytes / 1e9).toFixed(0)} GB`
+ (m.kv_seqs != null ? ` · ${m.kv_seqs} sequences` : "");
}
setV("t-util", fmt.pct(g.util), "");
$("t-util-s").textContent = g.temp != null ? `${Math.round(g.temp)}°C · ${Math.round(g.power)} / ${Math.round(g.power_limit)} W` : "";
$("t-mem").innerHTML = g.mem_used != null ? `${(g.mem_used / 1024).toFixed(1)}<small>/ ${(g.mem_total / 1024).toFixed(0)} GiB</small>` : "—";
@ -354,11 +392,76 @@ function render(s) {
chart("c-util", h.map((p) => p.util), "var(--c2)", 100, (v) => fmt.pct(v));
chart("c-kv", h.map((p) => p.kv), "var(--c3)", null, (v) => fmt.n(v, 1) + "%");
// Fixed scales so the shape means something: 0–100 °C, and 0 to the board power limit.
chart("c-temp", h.map((p) => p.temp), "var(--c4)", 100, (v) => Math.round(v) + " °C");
$("c-temp-max").textContent = g.temp == null ? "not reported on this hardware" : "0–100 °C";
const plim = g.power_limit || 600;
$("c-power-max").textContent = g.power == null ? "not reported on this hardware" : `0–${Math.round(plim)} W`;
chart("c-power", h.map((p) => p.power), "var(--c5)", plim, (v) => Math.round(v) + " W");
// Apple Silicon reports neither through any API that works without root (powermetrics
// needs sudo), so hide the panels instead of drawing two charts that can never fill.
const hasTP = g.temp != null || g.power != null || h.some((p) => p.temp != null || p.power != null);
$("p-temp").hidden = !hasTP;
$("p-power").hidden = !hasTP;
$("p-nogpu").hidden = hasTP;
$("gpu-charts").classList.toggle("four", false);
if (!hasTP) {
$("nogpu-why").textContent = s.kind === "apple"
? "macOS only exposes GPU temperature and power to root (powermetrics), so they aren't charted here."
: "not reported by this hardware";
} else {
chart("c-temp", h.map((p) => p.temp), "var(--c4)", 100, (v) => Math.round(v) + " °C");
$("c-temp-max").textContent = "0–100 °C";
const plim = g.power_limit || 600;
$("c-power-max").textContent = `0–${Math.round(plim)} W`;
chart("c-power", h.map((p) => p.power), "var(--c5)", plim, (v) => Math.round(v) + " W");
}
renderRuns(s);
}
function renderRuns(s) {
const runs = s.runs || [], body = $("runs-body"), foot = $("runs-foot");
$("runs-empty").hidden = runs.length > 0;
$("runs").hidden = s.backend !== "mlx" && runs.length === 0;
body.textContent = "";
foot.textContent = "";
if (!runs.length) {
$("runs-sub").textContent = s.backend === "mlx" ? "" : "per-request timings are only collected on MLX";
return;
}
const clock = (t) => new Date(t * 1000).toLocaleTimeString(undefined, { hour12: false });
const cell = (tr, text, cls) => {
const td = document.createElement("td");
td.textContent = text;
if (cls) td.className = cls;
tr.append(td);
return td;
};
const dash = (v, f) => (v == null ? ["—", "none"] : [f(v), ""]);
for (const r of runs) {
const tr = document.createElement("tr");
if (r.aborted) tr.className = "aborted";
cell(tr, clock(r.t));
cell(tr, ...dash(r.dur, fmt.secs));
cell(tr, ...dash(r.ttft, fmt.secs));
cell(tr, ...dash(r.prompt, (v) => fmt.big(v)));
cell(tr, ...dash(r.prompt_tps, (v) => fmt.n(v, 0)));
cell(tr, ...dash(r.gen, (v) => fmt.big(v)));
cell(tr, ...dash(r.gen_tps, (v) => fmt.n(v, 1)));
cell(tr, ...dash(r.kv_peak_pct, (v) => fmt.n(v, 1) + "%"));
body.append(tr);
}
// Averages over the runs shown, so the row means the same thing as the table above it.
const avg = (k) => {
const xs = runs.map((r) => r[k]).filter((v) => v != null);
return xs.length ? xs.reduce((a, b) => a + b, 0) / xs.length : null;
};
const peak = Math.max(...runs.map((r) => r.kv_peak_pct ?? 0));
const tr = document.createElement("tr");
cell(tr, `${runs.length} shown`);
cell(tr, ...dash(avg("dur"), fmt.secs));
cell(tr, ...dash(avg("ttft"), fmt.secs));
cell(tr, ...dash(avg("prompt"), (v) => fmt.big(v)));
cell(tr, ...dash(avg("prompt_tps"), (v) => fmt.n(v, 0)));
cell(tr, ...dash(avg("gen"), (v) => fmt.big(v)));
cell(tr, ...dash(avg("gen_tps"), (v) => fmt.n(v, 1)));
cell(tr, ...dash(peak > 0 ? peak : null, (v) => fmt.n(v, 1) + "%"));
foot.append(tr);
$("runs-sub").textContent = "newest first · averages below · tok/s split at first token";
}
const CW = 300, CH = 90, CN = 300; // chart viewBox width/height, max samples