Skip to content

Add monitoring center for API usage metrics#186

Merged
liuw1535 merged 1 commit into
yanshifrom
codex/add-monitoring-dashboard-for-yanshi-branch
Jun 4, 2026
Merged

Add monitoring center for API usage metrics#186
liuw1535 merged 1 commit into
yanshifrom
codex/add-monitoring-dashboard-for-yanshi-branch

Conversation

@liuw1535

@liuw1535 liuw1535 commented Jun 4, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Provide a lightweight monitoring center to show API call counts and token usage for demo/system presentation, with selectable ranges (7/14/30 days), summary cards (requests, tokens, TPM, RPM, RDP) and a token-ranked per-model donut chart.

Description

  • Add a persisted usage statistics store src/utils/usageStats.js that keeps daily buckets (up to 30 days) and exposes usageStats and setUsageMetrics for recording and summarizing metrics; data persisted to data/usage-stats.json.
  • Insert a request-monitoring middleware in src/server/index.js that infers model names for common API paths and records metrics on response finish (only tracks /v1/, /v1beta/, /cli/v1/).
  • Wire usage recording into response paths by calling setUsageMetrics from handlers src/server/handlers/openai.js, src/server/handlers/gemini.js, src/server/handlers/claude.js, and src/server/handlers/geminicli.js for stream/fake/non-stream branches so usage/status are captured.
  • Add admin API GET /admin/monitor/usage in src/routes/admin.js that returns usageStats.getSummary(days) for the frontend.
  • Implement frontend Monitor tab: public/index.html (tab and page), new UI logic in public/js/monitor.js, tab integration in public/js/ui.js and public/js/main.js, and styles in public/css/pages.css to render the five summary cards and a conic-gradient donut chart with model token distribution.

Testing

  • Ran syntax checks: node --check on modified server and frontend files (all succeeded).
  • Performed a smoke test using the bundled usage API: imported usageStats and executed recording calls then validated usageStats.getSummary(7) contains the recorded requests and model distribution (script run succeeded and printed usage stats smoke test passed).
  • Verified basic integration by running the linter/quick checks used above and ensuring no runtime parse errors across changed files.

Codex Task

@liuw1535 liuw1535 merged commit 6ad3e60 into yanshi Jun 4, 2026
7 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant