-
Notifications
You must be signed in to change notification settings - Fork 2
feat: bot performance monitoring #218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8bccce5
feat: add performance monitoring module and API routes
BillChirico 3112bc1
test: add performance monitor and API route tests (36 tests)
BillChirico e945823
feat: add performance dashboard with charts and threshold editor
BillChirico 3db731d
Merge origin/main into feat/issue-144
429ee46
style: fix lint issues after merge
9f9e921
Merge latest origin/main into feat/issue-144
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| /** | ||
| * Performance Metrics Route | ||
| * | ||
| * Returns bot performance metrics including memory usage, CPU utilization, | ||
| * response time statistics, and configurable alert thresholds. | ||
| * | ||
| * All endpoints require x-api-secret authentication. | ||
| */ | ||
|
|
||
| import { Router } from 'express'; | ||
| import { PerformanceMonitor } from '../../modules/performanceMonitor.js'; | ||
| import { isValidSecret } from '../middleware/auth.js'; | ||
|
|
||
| const router = Router(); | ||
|
|
||
| /** | ||
| * @openapi | ||
| * /performance: | ||
| * get: | ||
| * tags: | ||
| * - Performance | ||
| * summary: Get performance metrics snapshot | ||
| * description: > | ||
| * Returns the full performance snapshot including current stats, | ||
| * time-series data for memory/CPU, response time samples and summary, | ||
| * and configured alert thresholds. Requires x-api-secret header. | ||
| * parameters: | ||
| * - in: header | ||
| * name: x-api-secret | ||
| * schema: | ||
| * type: string | ||
| * required: true | ||
| * responses: | ||
| * "200": | ||
| * description: Performance snapshot | ||
| * "401": | ||
| * description: Unauthorized | ||
| */ | ||
| router.get('/', (req, res) => { | ||
| if (!isValidSecret(req.headers['x-api-secret'])) { | ||
| return res.status(401).json({ error: 'Unauthorized' }); | ||
| } | ||
|
|
||
| const monitor = PerformanceMonitor.getInstance(); | ||
| const snapshot = monitor.getSnapshot(); | ||
| res.json(snapshot); | ||
| }); | ||
|
|
||
| /** | ||
| * @openapi | ||
| * /performance/thresholds: | ||
| * get: | ||
| * tags: | ||
| * - Performance | ||
| * summary: Get alert thresholds | ||
| * security: | ||
| * - apiSecret: [] | ||
| * responses: | ||
| * "200": | ||
| * description: Current thresholds | ||
| * put: | ||
| * tags: | ||
| * - Performance | ||
| * summary: Update alert thresholds | ||
| * description: Partial update — only supplied fields are changed. | ||
| * security: | ||
| * - apiSecret: [] | ||
| * requestBody: | ||
| * required: true | ||
| * content: | ||
| * application/json: | ||
| * schema: | ||
| * type: object | ||
| * properties: | ||
| * memoryHeapMb: | ||
| * type: number | ||
| * memoryRssMb: | ||
| * type: number | ||
| * cpuPercent: | ||
| * type: number | ||
| * responseTimeMs: | ||
| * type: number | ||
| * responses: | ||
| * "200": | ||
| * description: Updated thresholds | ||
| */ | ||
| router.get('/thresholds', (req, res) => { | ||
| if (!isValidSecret(req.headers['x-api-secret'])) { | ||
| return res.status(401).json({ error: 'Unauthorized' }); | ||
| } | ||
|
|
||
| const monitor = PerformanceMonitor.getInstance(); | ||
| res.json(monitor.getThresholds()); | ||
| }); | ||
|
|
||
| router.put('/thresholds', (req, res) => { | ||
| if (!isValidSecret(req.headers['x-api-secret'])) { | ||
| return res.status(401).json({ error: 'Unauthorized' }); | ||
| } | ||
|
|
||
| const allowed = new Set(['memoryHeapMb', 'memoryRssMb', 'cpuPercent', 'responseTimeMs']); | ||
| const update = {}; | ||
|
|
||
| for (const [key, val] of Object.entries(req.body ?? {})) { | ||
| if (!allowed.has(key)) continue; | ||
| const num = Number(val); | ||
| if (!Number.isFinite(num) || num <= 0) { | ||
| return res.status(400).json({ error: `Invalid value for ${key}: must be a positive number` }); | ||
| } | ||
| update[key] = num; | ||
| } | ||
|
|
||
| if (Object.keys(update).length === 0) { | ||
| return res.status(400).json({ error: 'No valid threshold fields provided' }); | ||
| } | ||
|
|
||
| const monitor = PerformanceMonitor.getInstance(); | ||
| monitor.setThresholds(update); | ||
| res.json(monitor.getThresholds()); | ||
| }); | ||
|
|
||
| export default router; |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.