UNPKG

@gabrielmaialva33/mcp-filesystem

Version:
54 lines 1.65 kB
export class OperationMetrics { static instance; operations = {}; startTime; constructor() { this.startTime = performance.now(); } static getInstance() { if (!OperationMetrics.instance) { OperationMetrics.instance = new OperationMetrics(); } return OperationMetrics.instance; } startOperation(name) { if (!this.operations[name]) { this.operations[name] = { count: 0, errors: 0, totalTime: 0 }; } const startTime = performance.now(); this.operations[name].count++; return () => { const endTime = performance.now(); const duration = endTime - startTime; this.operations[name].totalTime += duration; }; } recordError(name) { if (!this.operations[name]) { this.operations[name] = { count: 0, errors: 0, totalTime: 0 }; } this.operations[name].errors++; } getMetrics() { const result = {}; for (const [name, data] of Object.entries(this.operations)) { result[name] = { count: data.count, errors: data.errors, avgTime: data.count > 0 ? data.totalTime / data.count : 0, }; } result['uptime_ms'] = { count: 1, errors: 0, avgTime: performance.now() - this.startTime, }; return result; } reset() { this.operations = {}; this.startTime = performance.now(); } } export const metrics = OperationMetrics.getInstance(); //# sourceMappingURL=index.js.map