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
@@ -178,6 +178,23 @@ async fn session_holds_context_and_persists_usage() {
|
||||
assert_eq!(s["sessions"], 1);
|
||||
assert_eq!(s["messages"], 4);
|
||||
assert_eq!(s["completion_tokens"], 10);
|
||||
// Expanded dashboard payload: totals, per-session/daily breakdown, and the
|
||||
// live engine status + since-startup performance gauge layered on top.
|
||||
assert_eq!(
|
||||
s["total_tokens"],
|
||||
s["prompt_tokens"].as_u64().unwrap() + s["completion_tokens"].as_u64().unwrap()
|
||||
);
|
||||
assert_eq!(s["tool_calls"], 0);
|
||||
assert_eq!(s["by_session"].as_array().unwrap().len(), 1);
|
||||
assert_eq!(s["by_session"][0]["messages"], 4);
|
||||
assert_eq!(s["daily"].as_array().unwrap().len(), 1);
|
||||
assert_eq!(s["engine"]["model"], "test-model");
|
||||
assert_eq!(s["engine"]["max_context"], 8192);
|
||||
assert_eq!(s["engine"]["busy"], false);
|
||||
// Two non-stream completions were served and recorded by the perf meter,
|
||||
// whose token-weighted decode speed comes from the mock's DONE timings.
|
||||
assert_eq!(s["perf"]["requests"], 2);
|
||||
assert!(s["perf"]["decode_tps"].as_f64().unwrap() > 0.0);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
Reference in new issue
Block a user