Add comprehensive disk monitoring with real-time metrics: - Backend API endpoints for disk/memory metrics (local + remote) - Admin UI page with CSP-compliant DOM rendering - Health status indicators with color-coded thresholds - SSH-based remote metrics collection from OVH VPS - Auto-refresh every 5 minutes Backend: - src/models/DiskMetrics.model.js: Metrics collection model - src/controllers/diskMetrics.controller.js: 3 admin endpoints - src/routes/diskMetrics.routes.js: Admin-authenticated routes - src/routes/index.js: Register disk-metrics routes Frontend: - public/admin/disk-monitoring.html: Admin dashboard page - public/js/admin-disk-monitoring.js: CSP-compliant UI rendering - public/js/components/navbar-admin.js: Add disk monitoring link Documentation: - deployment-quickstart/UPTIME_MONITORING_SETUP.md API endpoints: - GET /api/admin/disk-metrics (all systems) - GET /api/admin/disk-metrics/local (dev system) - GET /api/admin/disk-metrics/remote (production VPS) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
99 lines
2.4 KiB
JavaScript
99 lines
2.4 KiB
JavaScript
/**
|
|
* Disk Metrics Controller
|
|
* Handles API requests for disk usage and system metrics
|
|
*/
|
|
|
|
const DiskMetrics = require('../models/DiskMetrics.model');
|
|
const logger = require('../utils/logger.util');
|
|
|
|
/**
|
|
* Get all metrics (local + remote)
|
|
* GET /api/admin/disk-metrics
|
|
*/
|
|
async function getAllMetrics(req, res) {
|
|
try {
|
|
logger.info('Fetching disk metrics for all systems');
|
|
const metrics = await DiskMetrics.getAllMetrics();
|
|
|
|
// Add health status for each system
|
|
if (metrics.local && metrics.local.usedPercent !== undefined) {
|
|
metrics.local.health = DiskMetrics.getHealthStatus(metrics.local.usedPercent);
|
|
}
|
|
|
|
if (metrics.remote && metrics.remote.usedPercent !== undefined) {
|
|
metrics.remote.health = DiskMetrics.getHealthStatus(metrics.remote.usedPercent);
|
|
}
|
|
|
|
res.json({
|
|
success: true,
|
|
data: metrics
|
|
});
|
|
} catch (error) {
|
|
logger.error('Get all metrics error:', error);
|
|
res.status(500).json({
|
|
success: false,
|
|
error: 'Failed to fetch disk metrics',
|
|
message: error.message
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get local metrics only
|
|
* GET /api/admin/disk-metrics/local
|
|
*/
|
|
async function getLocalMetrics(req, res) {
|
|
try {
|
|
logger.info('Fetching local disk metrics');
|
|
const metrics = await DiskMetrics.getLocalMetrics();
|
|
|
|
if (metrics.usedPercent !== undefined) {
|
|
metrics.health = DiskMetrics.getHealthStatus(metrics.usedPercent);
|
|
}
|
|
|
|
res.json({
|
|
success: true,
|
|
data: metrics
|
|
});
|
|
} catch (error) {
|
|
logger.error('Get local metrics error:', error);
|
|
res.status(500).json({
|
|
success: false,
|
|
error: 'Failed to fetch local metrics',
|
|
message: error.message
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get remote metrics only
|
|
* GET /api/admin/disk-metrics/remote
|
|
*/
|
|
async function getRemoteMetrics(req, res) {
|
|
try {
|
|
logger.info('Fetching remote disk metrics');
|
|
const metrics = await DiskMetrics.getRemoteMetrics();
|
|
|
|
if (metrics.usedPercent !== undefined) {
|
|
metrics.health = DiskMetrics.getHealthStatus(metrics.usedPercent);
|
|
}
|
|
|
|
res.json({
|
|
success: true,
|
|
data: metrics
|
|
});
|
|
} catch (error) {
|
|
logger.error('Get remote metrics error:', error);
|
|
res.status(500).json({
|
|
success: false,
|
|
error: 'Failed to fetch remote metrics',
|
|
message: error.message
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
getAllMetrics,
|
|
getLocalMetrics,
|
|
getRemoteMetrics
|
|
};
|