Add a live statistics dashboard over persistent history
Replace the four-row stats modal with a real dashboard — our own angle on the reference's ephemeral request monitor: because our context lives in SQLite we can aggregate over ALL history, not just the last N requests. Backend: - Usage carries the engine's prompt_ms/decode_ms (from DONE); a token- weighted in-memory PerfMeter in ChatService records every served request (complete + stream) and exposes decode/prefill tok/s. - store::Stats grows total_tokens, tool_calls (json_array_length over assistant tool_calls_json), a per-session breakdown (busiest first) and a per-UTC-day token series; all over existing columns, no schema change, still behind the Store trait. - GET /api/stats returns the store aggregates flattened plus a live engine status (model, max_context, busy) and the perf gauge. Frontend (mobile-first, vanilla, i18n catalog): - Overview cards: engine state dot + model + context, decode speed (run average) + prefill, total/prompt/completion tokens, sessions + messages, tool calls, requests served. - Daily stacked prompt/completion bar chart (continuous zero-filled UTC window, last 30 days) and per-session token-share bars. - Polls every 2s while open, re-renders only on change; closes via button, backdrop or Escape. Tests: new store breakdown test + extended stats integration assertions (124 passed, 2 ignored). Verified live on the real engine: decode/prefill gauge populated from DONE timings; dashboard renders on desktop.
This commit is contained in:
1 parent
e79ee0e20e
commit
765c197b95
11 files changed
+642
-42
No files matched your search
+77
-3
@@ -210,9 +210,83 @@ details.thinking .reasoning {
|
||||
padding: 20px; max-width: 420px; width: 100%;
|
||||
}
|
||||
.modal-card h2 { margin: 0 0 12px; font-size: 1.1rem; }
|
||||
#stats-body { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; margin: 0 0 16px; }
|
||||
#stats-body dt { color: var(--muted); }
|
||||
#stats-body dd { margin: 0; font-variant-numeric: tabular-nums; }
|
||||
|
||||
/* ---- Stats dashboard ---- */
|
||||
.stats-card {
|
||||
width: min(940px, 100%); max-width: 940px; max-height: 88dvh;
|
||||
display: flex; flex-direction: column; padding: 0; overflow: hidden;
|
||||
}
|
||||
.stats-head {
|
||||
display: flex; align-items: center; gap: 12px;
|
||||
padding: 14px 18px; border-bottom: 1px solid var(--border);
|
||||
background: var(--panel); flex: 0 0 auto;
|
||||
}
|
||||
.stats-head h2 { margin: 0; font-size: 1.15rem; }
|
||||
.stats-live { flex: 1; font-size: 0.72rem; text-align: right; font-variant-numeric: tabular-nums; }
|
||||
.stats-head .btn.icon { min-height: 36px; padding: 6px 10px; font-size: 1rem; }
|
||||
.stats-content { padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 22px; }
|
||||
|
||||
/* Overview cards: 2-up on phones, 3-up from 700px. */
|
||||
.stat-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
|
||||
.stat-card {
|
||||
background: var(--panel-2); border: 1px solid var(--border);
|
||||
border-radius: 12px; padding: 12px 14px; min-width: 0;
|
||||
}
|
||||
.stat-card .label {
|
||||
font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.7px; color: var(--muted);
|
||||
}
|
||||
.stat-card .value {
|
||||
font-size: 1.5rem; font-weight: 600; line-height: 1.25; margin-top: 4px;
|
||||
font-variant-numeric: tabular-nums; overflow-wrap: anywhere;
|
||||
}
|
||||
.stat-card .sub { font-size: 0.73rem; color: var(--muted); margin-top: 3px; overflow-wrap: anywhere; }
|
||||
.stat-card.engine .value { display: flex; align-items: center; gap: 8px; font-size: 1.1rem; }
|
||||
.stat-card .model {
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
||||
font-size: 0.72rem; color: var(--muted); margin-top: 5px; overflow-wrap: anywhere;
|
||||
}
|
||||
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: 0 0 auto; }
|
||||
.dot.idle { background: #3fb950; }
|
||||
.dot.busy { background: #d29922; }
|
||||
|
||||
/* Section headings inside the dashboard. */
|
||||
.stat-section > h3 { margin: 0; font-size: 0.95rem; }
|
||||
.stat-section > .sub { font-size: 0.73rem; color: var(--muted); margin: 2px 0 12px; }
|
||||
.stat-empty { color: var(--muted); font-size: 0.85rem; padding: 10px 0; }
|
||||
|
||||
/* Daily activity chart: stacked prompt/completion bars (pure CSS, responsive). */
|
||||
.chart-bars { display: flex; align-items: flex-end; gap: 3px; height: 132px; }
|
||||
.chart-bars .bar {
|
||||
flex: 1 1 0; min-width: 0; height: 100%;
|
||||
display: flex; flex-direction: column; justify-content: flex-end;
|
||||
}
|
||||
.chart-bars .bar i { display: block; width: 100%; }
|
||||
.chart-bars .bar i.prompt { background: var(--accent-press); }
|
||||
.chart-bars .bar i.completion { background: var(--accent); border-radius: 3px 3px 0 0; }
|
||||
.chart-bars .bar:hover i { filter: brightness(1.18); }
|
||||
.chart-x { display: flex; justify-content: space-between; gap: 8px; font-size: 0.66rem; color: var(--muted); margin-top: 6px; }
|
||||
.chart-legend { display: flex; gap: 14px; margin-top: 10px; font-size: 0.72rem; color: var(--muted); }
|
||||
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
|
||||
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
|
||||
.swatch.prompt { background: var(--accent-press); }
|
||||
.swatch.completion { background: var(--accent); }
|
||||
|
||||
/* Per-session breakdown: relative token-share bars, busiest first. */
|
||||
.sess-stats { display: flex; flex-direction: column; gap: 12px; }
|
||||
.sess-stat { min-width: 0; }
|
||||
.sess-stat.current .name { color: var(--accent); }
|
||||
.sess-stat-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
|
||||
.sess-stat-top .name { font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.sess-stat-top .tok { font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; flex: 0 0 auto; }
|
||||
.sess-bar { display: flex; height: 8px; border-radius: 5px; overflow: hidden; background: var(--bg); margin: 5px 0 4px; }
|
||||
.sess-bar i { display: block; height: 100%; }
|
||||
.sess-bar i.prompt { background: var(--accent-press); }
|
||||
.sess-bar i.completion { background: var(--accent); }
|
||||
.sess-stat-sub { font-size: 0.7rem; color: var(--muted); }
|
||||
|
||||
@media (min-width: 700px) {
|
||||
.stat-cards { grid-template-columns: repeat(3, 1fr); }
|
||||
}
|
||||
#dialog-msg { margin: 0 0 16px; }
|
||||
#dialog-input {
|
||||
width: 100%; background: var(--panel-2); color: var(--text);
|
||||
|
||||
Reference in new issue
Block a user