feat: enhance usage analytics dashboard (#666)

- visualize input, output, and cache token segments in usage charts
- add usage period selector for 7d, 30d, 90d, and 365d
- guard usage stats against stale overlapping period requests
- normalize blank model usage into unknown buckets
- add client and server coverage for usage analytics behavior
This commit is contained in:
Zhicheng Han
2026-05-13 01:41:49 +02:00
committed by GitHub
parent 57cdf87bef
commit c2068302c3
18 changed files with 683 additions and 113 deletions
@@ -450,8 +450,9 @@ export async function usageStats(ctx: any) {
const totalSessions = local.sessions + hermes.sessions
const modelMap = new Map<string, UsageStatsModelRow>()
for (const m of [...local.by_model, ...hermes.by_model].filter(m => m.model)) {
const existing = modelMap.get(m.model)
for (const m of [...local.by_model, ...hermes.by_model]) {
const model = (m.model || '').trim() || 'unknown'
const existing = modelMap.get(model)
if (existing) {
existing.input_tokens += m.input_tokens
existing.output_tokens += m.output_tokens
@@ -460,7 +461,7 @@ export async function usageStats(ctx: any) {
existing.reasoning_tokens += m.reasoning_tokens
existing.sessions += m.sessions
} else {
modelMap.set(m.model, { ...m })
modelMap.set(model, { ...m, model })
}
}