jsdocs, move observer

This commit is contained in:
Alex Holliday committed 2025-07-23 14:31:40 -07:00
1 parent cfebc770fd
commit da49e15589
2 files changed
+49 -8

No files matched your search

+37 -7
View File
@@ -1,19 +1,48 @@
import { asyncHandler } from "../utils/errorUtils.js"; import { asyncHandler } from "../utils/errorUtils.js";
const SERVICE_NAME = "diagnosticController"; const SERVICE_NAME = "diagnosticController";
/**
const obs = new PerformanceObserver((items) => { * Diagnostic Controller
const entry = items.getEntries()[0]; *
performance.clearMarks(); * Handles system diagnostic and monitoring requests including system statistics,
}); * performance metrics, and health checks.
obs.observe({ entryTypes: ["measure"] }); *
* @class DiagnosticController
* @description Manages system diagnostics and performance monitoring
*/
class DiagnosticController { class DiagnosticController {
/**
* Creates an instance of DiagnosticController.
*
* @param {Object} dependencies - The dependencies required by the controller
* @param {Object} dependencies.diagnosticService - Service for system diagnostics and monitoring
*/
constructor({ diagnosticService }) { constructor({ diagnosticService }) {
this.diagnosticService = diagnosticService; this.diagnosticService = diagnosticService;
} }
/**
* 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( getSystemStats = asyncHandler(
async (req, res, next) => { async (req, res) => {
const diagnostics = await this.diagnosticService.getSystemStats(); const diagnostics = await this.diagnosticService.getSystemStats();
return res.success({ return res.success({
msg: "OK", msg: "OK",
@@ -24,4 +53,5 @@ class DiagnosticController {
"getSystemStats" "getSystemStats"
); );
} }
export default DiagnosticController; export default DiagnosticController;
+12 -1
View File
@@ -5,7 +5,18 @@ const SERVICE_NAME = "diagnosticService";
class DiagnosticService { class DiagnosticService {
static SERVICE_NAME = SERVICE_NAME; static SERVICE_NAME = SERVICE_NAME;
constructor() {} constructor() {
/**
* Performance Observer for monitoring system performance metrics.
* Clears performance marks after each measurement to prevent memory leaks.
*/
const obs = new PerformanceObserver((items) => {
// Get the first entry but we don't need to store it
items.getEntries()[0];
performance.clearMarks();
});
obs.observe({ entryTypes: ["measure"] });
}
getCPUUsage = async () => { getCPUUsage = async () => {
const startUsage = process.cpuUsage(); const startUsage = process.cpuUsage();