Conversation
- PerformanceMonitor singleton with circular buffer time-series storage - Samples memory (heap/RSS) and CPU every 30s - Records command and API response times - Configurable alert thresholds with callback hooks (5min cooldown) - GET /api/v1/performance — full snapshot (auth required) - GET/PUT /api/v1/performance/thresholds — threshold management - Wired into bot startup/shutdown lifecycle - API response time middleware on all /api/v1 routes - Command execution timing in slash command handler
- /dashboard/performance page with recharts area/bar charts - Memory usage (heap + RSS) over time — AreaChart - CPU utilization over time — AreaChart - Response time histogram (500ms buckets) — BarChart - Recent response times table with type badges - Alert threshold editor (save via PUT /api/v1/performance/thresholds) - KPI cards for heap, RSS, CPU, uptime, and percentile response times - Auto-refreshes every 30s; manual refresh button - Sidebar: Activity icon + Performance nav link - Next.js proxy routes: GET/PUT /api/performance and /api/performance/thresholds
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (15)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Pull request overview
Adds real-time performance monitoring (memory/CPU/response times), alert thresholds, and a dashboard UI to visualize and configure metrics.
Changes:
- Introduces a backend
PerformanceMonitorsingleton with circular-buffer time series and threshold-based alerting. - Adds
/api/v1/performance+/api/v1/performance/thresholdsendpoints and wires response-time sampling into the API + command handler. - Adds a Next.js dashboard page with charts, recent samples table, and a threshold editor (plus sidebar nav link).
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| web/src/components/layout/sidebar.tsx | Adds a “Performance” nav item pointing to the new dashboard page |
| web/src/components/dashboard/performance-dashboard.tsx | Implements dashboard UI: charts, recent samples table, fetch/auto-refresh, and threshold editor |
| web/src/app/dashboard/performance/page.tsx | Provides the dashboard route entry that renders the new performance dashboard component |
| web/src/app/api/performance/route.ts | Adds authenticated Next.js proxy endpoint for performance snapshot |
| web/src/app/api/performance/thresholds/route.ts | Adds authenticated Next.js proxy endpoints for reading/updating thresholds |
| src/modules/performanceMonitor.js | Adds monitor singleton, circular buffers, sampling, summary stats, and alerting |
| src/index.js | Wires monitor startup/shutdown and records command execution response times |
| src/api/server.js | Adds API middleware to record per-request response times |
| src/api/routes/performance.js | Adds performance snapshot + thresholds endpoints (x-api-secret auth) |
| src/api/index.js | Mounts the new performance router |
| tests/modules/performanceMonitor.test.js | Adds unit tests for CircularBuffer and PerformanceMonitor behavior |
| tests/api/routes/performance.test.js | Adds integration tests for the performance endpoints |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
| Filename | Overview |
|---|---|
| src/modules/performanceMonitor.js | implemented circular buffer-based performance monitoring with memory, CPU, and response time tracking; clean singleton pattern with proper error handling and Winston logging |
| src/api/routes/performance.js | added three performance API endpoints with proper authentication, input validation, and OpenAPI documentation |
| web/src/components/dashboard/performance-dashboard.tsx | comprehensive performance dashboard with real-time charts, metrics cards, threshold editor, and auto-refresh; proper error handling and loading states |
| tests/modules/performanceMonitor.test.js | comprehensive test coverage for CircularBuffer and PerformanceMonitor including edge cases, alerts, cooldowns, and time-series sampling |
| tests/api/routes/performance.test.js | thorough API endpoint tests covering authentication, authorization, input validation, and response structure |
Sequence Diagram
sequenceDiagram
participant Bot as Discord Bot
participant PM as PerformanceMonitor
participant API as Express API
participant Next as Next.js Dashboard
participant User as Browser
Note over Bot,PM: Startup
Bot->>PM: start() on ClientReady
PM->>PM: Start 30s interval timer
Note over PM: Every 30 seconds
PM->>PM: Sample memory (heap, RSS)
PM->>PM: Sample CPU (process.cpuUsage)
PM->>PM: Store in CircularBuffer (120 samples)
PM->>PM: Check thresholds & fire alerts
Note over Bot,PM: Command Execution
User->>Bot: /command
Bot->>Bot: Start timer
Bot->>Bot: Execute command
Bot->>PM: recordResponseTime(name, duration)
PM->>PM: Store in CircularBuffer (480 samples)
PM->>PM: Check threshold
Note over API,PM: API Request
User->>API: GET /api/v1/endpoint
API->>API: Start timer (middleware)
API->>API: Handle request
API->>PM: recordResponseTime(label, duration)
Note over User,Next: Dashboard View
User->>Next: Open /dashboard/performance
Next->>Next: Verify NextAuth token
Next->>API: GET /api/v1/performance (proxy)
API->>API: Validate x-api-secret
API->>PM: getSnapshot()
PM-->>API: {current, timeSeries, responseTimes, summary}
API-->>Next: JSON response
Next-->>User: Render charts & metrics
Note over User,Next: Update Thresholds
User->>Next: PUT /api/performance/thresholds
Next->>Next: Verify NextAuth token
Next->>API: PUT /api/v1/performance/thresholds
API->>API: Validate input
API->>PM: setThresholds(values)
PM-->>API: Updated thresholds
API-->>Next: JSON response
Next-->>User: Show success message
Note over Bot,PM: Shutdown
Bot->>PM: stop()
PM->>PM: clearInterval(timer)
Last reviewed commit: 9f9e921
Summary
Adds real-time performance monitoring and alerting for the bot with a dashboard UI.
Features
Architecture
Backend
src/modules/performanceMonitor.js— singleton with circular buffer time-series storage (no DB, in-memory)src/api/routes/performance.js— GET /api/v1/performance (snapshot), GET/PUT /api/v1/performance/thresholdsFrontend
web/src/app/dashboard/performance/page.tsx— dashboard pageweb/src/components/dashboard/performance-dashboard.tsx— recharts charts + threshold editorweb/src/app/api/performance/route.ts— Next.js proxy (GET)web/src/app/api/performance/thresholds/route.ts— Next.js proxy (GET/PUT)Tests
PerformanceMonitorandCircularBufferFiles Changed
src/modules/performanceMonitor.js— new: monitor singletonsrc/api/routes/performance.js— new: API routessrc/api/index.js— mount /performance routersrc/api/server.js— response time middlewaresrc/index.js— lifecycle wiring + command timingweb/src/app/api/performance/route.ts— new: proxy GETweb/src/app/api/performance/thresholds/route.ts— new: proxy GET/PUTweb/src/app/dashboard/performance/page.tsx— new: pageweb/src/components/dashboard/performance-dashboard.tsx— new: charts + UIweb/src/components/layout/sidebar.tsx— add Performance nav linktests/modules/performanceMonitor.test.js— new: 24 teststests/api/routes/performance.test.js— new: 12 tests