Files
Checkmate/server/controllers/diagnosticController.js
T

57 lines
1.8 KiB
JavaScript
Raw Normal View History

2025-04-20 11:29:53 -07:00
const SERVICE_NAME = "diagnosticController";
2025-07-24 15:06:46 -07:00
import BaseController from "./baseController.js";
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-07-24 15:06:46 -07:00
class DiagnosticController extends BaseController {
2025-07-23 14:31:40 -07:00
/**
* Creates an instance of DiagnosticController.
2025-07-25 10:16:29 -07:00
* @param {Object} commonDependencies - Common dependencies injected into the controller
2025-07-23 14:31:40 -07:00
* @param {Object} dependencies - The dependencies required by the controller
* @param {Object} dependencies.diagnosticService - Service for system diagnostics and monitoring
*/
2025-07-25 10:16:29 -07:00
constructor(commonDependencies, { diagnosticService }) {
super(commonDependencies);
2025-07-23 14:28:16 -07:00
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
*/
2025-07-24 15:06:46 -07:00
getSystemStats = this.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;