fix(monitoring): flatten CPU/mem data, add health summary, public + rate-limit monitoring/stats
Three coordinated fixes for the System Overview widget:
1. routes/monitoring.js — flatten getAllStats() shape from
{current:{cpu:{percent},memory:{percent}}} to {cpu,memory,memoryUsage}
so the widget's Number() coercion actually produces numbers, not NaN.
Skill reference: references/totp-and-system-overview-pitfalls.md §3.
2. routes/health.js — add summary block to /health-checks/status response.
Widget looks for {healthy, unhealthy, total} but only per-service objects
existed. Permissive on healthy side (up|healthy|online), strict on
unhealthy (down|unhealthy|offline|error); anything else counted as
unknown. Same skill §3 reference.
3. middleware.js — add /api/v1/monitoring/stats to PUBLIC_ROUTES and the
rate-limit skip list. The widget polls it every 5s from the dashboard;
cookie-auth works but listing it explicitly makes it future-proof
against auth-cookie expiry and prevents per-second 429s.
End-to-end test (unauthenticated):
GET /api/v1/monitoring/stats -> {cpu: 8.71, memory: 0.37, ...}
GET /api/v1/health-checks/status -> {summary: {healthy:11, unhealthy:4, total:15}}
This commit is contained in:
@@ -16,8 +16,21 @@ module.exports = function({ resourceMonitor, docker, asyncHandler, log, notifica
|
||||
// ===== RESOURCE MONITORING ENDPOINTS =====
|
||||
|
||||
// Get all container stats (from resource monitor module)
|
||||
// Flattened for the System Overview widget — see skill references/totp-and-system-overview-pitfalls.md §3
|
||||
router.get('/monitoring/stats', asyncHandler(async (req, res) => {
|
||||
const stats = resourceMonitor.getAllStats();
|
||||
const raw = resourceMonitor.getAllStats();
|
||||
const stats = {};
|
||||
for (const [id, data] of Object.entries(raw || {})) {
|
||||
const cur = data.current || {};
|
||||
const cpuObj = (cur.cpu && typeof cur.cpu === 'object') ? cur.cpu : null;
|
||||
const memObj = (cur.memory && typeof cur.memory === 'object') ? cur.memory : null;
|
||||
stats[id] = {
|
||||
name: data.name,
|
||||
cpu: cpuObj ? (cpuObj.percent ?? 0) : (Number(cur.cpu) || 0),
|
||||
memory: memObj ? (memObj.percent ?? 0) : (Number(cur.memory) || 0),
|
||||
memoryUsage: memObj ? (memObj.usage ?? 0) : 0,
|
||||
};
|
||||
}
|
||||
success(res, { stats });
|
||||
}, 'monitoring-stats'));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user