Files
Checkmate/server/controllers/diagnosticController.js
T

57 lines
1.7 KiB
JavaScript
Raw Normal View History

import { asyncHandler } from "../utils/errorUtils.js";
2025-07-10 16:08:04 -07:00
2025-04-20 11:29:53 -07:00
const SERVICE_NAME = "diagnosticController";
2025-07-23 14:31:40 -07:00
/**
* Diagnostic Controller
*
* Handles system diagnostic and monitoring requests including system statistics,
* performance metrics, and health checks.
*
* @class DiagnosticController
* @description Manages system diagnostics and performance monitoring
*/
2025-04-20 11:29:53 -07:00
class DiagnosticController {
2025-07-23 14:31:40 -07:00
/**
* Creates an instance of DiagnosticController.
*
* @param {Object} dependencies - The dependencies required by the controller
* @param {Object} dependencies.diagnosticService - Service for system diagnostics and monitoring
*/
2025-07-23 14:28:16 -07:00
constructor({ diagnosticService }) {
this.diagnosticService = diagnosticService;
2025-04-20 11:29:53 -07:00
}
2025-07-23 14:31:40 -07:00
/**
* Retrieves comprehensive system statistics and performance metrics.
*
* @async
* @function getSystemStats
* @param {Object} req - Express request object
* @param {Object} res - Express response object
* @returns {Promise<Object>} Success response with system diagnostics data
* @description Returns system performance metrics, memory usage, CPU statistics,
* and other diagnostic information useful for monitoring system health.
* @example
* GET /diagnostics/stats
* // Response includes:
* // - Memory usage (heap, external, arrayBuffers)
* // - CPU usage statistics
* // - System uptime
* // - Performance metrics
* // - Database connection status
* // - Active processes/connections
*/
getSystemStats = asyncHandler(
2025-07-23 14:31:40 -07:00
async (req, res) => {
2025-07-23 14:28:16 -07:00
const diagnostics = await this.diagnosticService.getSystemStats();
2025-07-10 16:08:04 -07:00
return res.success({
msg: "OK",
data: diagnostics,
});
},
SERVICE_NAME,
"getSystemStats"
);
2025-04-20 11:29:53 -07:00
}
2025-07-23 14:31:40 -07:00
2025-04-20 11:29:53 -07:00
export default DiagnosticController;