Add monitoring center for API usage metrics#186
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Description
src/utils/usageStats.jsthat keeps daily buckets (up to 30 days) and exposesusageStatsandsetUsageMetricsfor recording and summarizing metrics; data persisted todata/usage-stats.json.src/server/index.jsthat infers model names for common API paths and records metrics on response finish (only tracks/v1/,/v1beta/,/cli/v1/).setUsageMetricsfrom handlerssrc/server/handlers/openai.js,src/server/handlers/gemini.js,src/server/handlers/claude.js, andsrc/server/handlers/geminicli.jsfor stream/fake/non-stream branches so usage/status are captured.GET /admin/monitor/usageinsrc/routes/admin.jsthat returnsusageStats.getSummary(days)for the frontend.public/index.html(tab and page), new UI logic inpublic/js/monitor.js, tab integration inpublic/js/ui.jsandpublic/js/main.js, and styles inpublic/css/pages.cssto render the five summary cards and a conic-gradient donut chart with model token distribution.Testing
node --checkon modified server and frontend files (all succeeded).usageStatsand executed recording calls then validatedusageStats.getSummary(7)contains the recorded requests and model distribution (script run succeeded and printedusage stats smoke test passed).Codex Task