Skip to content

feat: add monitoring center with channel/model stats and prompt logs - #4115

Closed
chensylz wants to merge 1 commit into
QuantumNous:mainfrom
chensylz:feat/monitor-center
Closed

chensylz wants to merge 1 commit into
QuantumNous:mainfrom
chensylz:feat/monitor-center

Conversation

@chensylz

@chensylz chensylz commented Apr 6, 2026 •

Copy link
Copy Markdown

Summary

Add a new Monitoring Center page with the following features:

Backend

  • GET /dashboard/overview - 综合概览 (requests, tokens, TPM, RPM, RPD)
  • GET /dashboard/channel/stats - 按渠道统计调用情况
  • GET /dashboard/model/stats - 按模型统计调用情况
  • GET /dashboard/logs/prompts - Prompt 日志查询(支持分页、筛选)
  • Log retention - 默认保留 7 天,可通过 LOG_RETENTION_DAYS 环境变量配置

Frontend

  • 监控中心页面 (/monitor)
    • 时间筛选:今天 / 最近7天 / 最近30天(上海时区)
    • 指标卡:请求数、Tokens、平均TPM、平均RPM、日均RPD
    • 模型用量分布图(Canvas 柱ッド图,Top 10)
    • 渠道用量分布图(同上)
    • Prompt 日志表格(支持查看详情弹窗)
    • 管理员全局视图,普通用户只看自己的数据
  • 侧边栏导航入口
  • 图标:ChartColumnIncreasing

Files changed

  • controller/monitor.go - 新增 API 控制器
  • model/monitor.go - 数据查询逻辑
  • model/log.go - 日志清理逻辑
  • router/dashboard.go - 路由注册
  • web/src/pages/Monitor/ - 前端页面
  • 多处前端配置(路由、导航、图标等)

Closes #4106

Summary by CodeRabbit

Release Notes

  • New Features
    • Added monitoring center dashboard for tracking API request metrics, tokens, and performance statistics.
    • Added dashboard analytics displaying top models and channels by usage.
    • Added searchable prompt log history viewer with detailed content modal.
    • Added automatic log cleanup with 7-day retention policy.
    • Added time-range filtering (today, 7 days, 30 days) for metrics analysis.

…ew metrics, and prompt logs

- Backend: 4 new API endpoints (/dashboard/channel/stats, /dashboard/model/stats,
  /dashboard/overview, /dashboard/logs/prompts) with scope-based user filtering
- Backend: log retention with configurable LOG_RETENTION_DAYS (default 7 days)
- Frontend: new Monitor page at /monitor with:
  * Time range filter (today / 7d / 30d) using Asia/Shanghai timezone
  * Overview metric cards (requests, tokens, TPM, RPM, RPD)
  * Model & channel usage distribution charts (canvas bar charts, top 10)
  * Paginated prompt log table with full-text modal viewer
  * Admin: global view; non-admin: own data only
- Navigation: sidebar entry, App.jsx route, icon, layout fixes
@coderabbitai

coderabbitai Bot commented Apr 6, 2026 •

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0a750f95-8ab0-40e0-98ce-37a7d6e46fbb

📥 Commits

Reviewing files that changed from the base of the PR and between eacc245 and f4f960d.

📒 Files selected for processing (16)
  • common/constants.go
  • common/init.go
  • controller/log.go
  • controller/monitor.go
  • main.go
  • model/log.go
  • model/monitor.go
  • router/dashboard.go
  • web/src/App.jsx
  • web/src/components/layout/PageLayout.jsx
  • web/src/components/layout/SiderBar.jsx
  • web/src/components/settings/personal/cards/NotificationSettings.jsx
  • web/src/helpers/render.jsx
  • web/src/hooks/common/useSidebar.js
  • web/src/pages/Monitor/index.jsx
  • web/src/pages/Setting/Operation/SettingsSidebarModulesAdmin.jsx

Walkthrough

Introduces a comprehensive monitoring dashboard feature. Backend adds configuration-driven log retention (days), automatic cleanup loop, and new REST APIs for dashboard statistics (channel/model/overview stats, prompt logs). Frontend adds Monitor page with metric cards, top-10 charts, searchable prompt logs table, and modal details view. Also enhances log recording to store prompt content for monitoring purposes.

Changes

Cohort / File(s) Summary
Log Retention Configuration
common/constants.go, common/init.go
Added LogRetentionDays constant and environment-backed initialization for log retention configuration.
Log Cleanup & Management
main.go, model/log.go, controller/log.go
Implemented automatic hourly log cleanup loop with configurable retention, enhanced log recording to capture prompt content, and removed validation guard in delete handler to support zero-timestamp cleanup triggers.
Backend Monitoring APIs
model/monitor.go, controller/monitor.go, router/dashboard.go
Added comprehensive dashboard query layer (channel/model stats, overview metrics, paginated prompt logs) with time-range normalization and user scoping; wired HTTP endpoints with standardized error/success responses.
Frontend Monitoring Center
web/src/pages/Monitor/index.jsx
Implemented Monitor page with time-window selection, API-driven metric cards, dual horizontal bar charts for top 10 channels/models, paginated prompt logs table with search/filtering, and details modal.
Frontend Routing & Layout
web/src/App.jsx, web/src/components/layout/PageLayout.jsx, web/src/components/layout/SiderBar.jsx
Added lazy-loaded Monitor route, updated layout logic to render sidebar and hide footer for monitor page, added monitor navigation item to sidebar menu.
Frontend Settings & Config
web/src/components/settings/personal/cards/NotificationSettings.jsx, web/src/pages/Setting/Operation/SettingsSidebarModulesAdmin.jsx, web/src/hooks/common/useSidebar.js
Added monitor module to user and admin sidebar settings with localized titles and descriptions; included in default admin configuration.
Frontend Icon Support
web/src/helpers/render.jsx
Extended icon renderer to support monitor key with ChartColumnIncreasing icon from lucide-react.

Sequence Diagram

sequenceDiagram
    participant User as Frontend:<br/>Monitor Page
    participant API as Backend:<br/>HTTP Routes
    participant Controller as Controller:<br/>monitor.go
    participant Model as Model:<br/>monitor.go
    participant DB as Database:<br/>Logs Table
    
    User->>API: GET /dashboard/overview<br/>GET /dashboard/channel/stats<br/>GET /dashboard/model/stats
    API->>Controller: Route to handler<br/>(extract time range, scope)
    Controller->>Model: Call GetDashboardOverview()<br/>GetDashboardChannelStats()<br/>GetDashboardModelStats()
    Model->>DB: Query logs filtered by<br/>time range + user scope
    DB-->>Model: Aggregated statistics
    Model->>Model: Normalize time range,<br/>compute avg metrics,<br/>attach channel names
    Model-->>Controller: Structured stat objects
    Controller->>Controller: Format response<br/>(code, data, message)
    Controller-->>API: JSON response
    API-->>User: Render metric cards<br/>& charts
    
    User->>API: GET /dashboard/logs/prompts<br/>(pagination, filters)
    API->>Controller: Extract query params
    Controller->>Model: GetDashboardPromptLogs()
    Model->>DB: Query with pagination,<br/>optional user/channel/model filters
    DB-->>Model: Paginated log entries
    Model->>Model: Extract prompt content,<br/>map channel IDs to names
    Model-->>Controller: Paginated log page object
    Controller-->>API: JSON response
    API-->>User: Render logs table,<br/>enable filtering
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • Calcium-Ion
  • creamlike1024

Poem

📊 A rabbit hops through logs so old,
Tidying shelves before they grow cold,
Dashboards bloom with charts divine,
Monitoring stats in perfect line! 🐰✨

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@chensylz chensylz closed this Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant