adpa-enterprise-framework-automation
Version:
Modular, standards-compliant Node.js/TypeScript automation framework for enterprise requirements, project, and data management. Provides CLI and API for BABOK v3, PMBOK 7th Edition, and DMBOK 2.0 (in progress). Production-ready Express.js API with TypeSpe
91 lines (88 loc) ⢠3.38 kB
JavaScript
/**
* Migration Performance Monitor
* Tracks and reports performance metrics during the migration
*/
import { AIProcessor } from '../../modules/ai/AIProcessor';
import fs from 'fs/promises';
import path from 'path';
class MigrationMonitor {
metricsPath;
snapshots;
constructor() {
this.metricsPath = path.join(process.cwd(), 'migration-metrics');
this.snapshots = [];
}
/**
* Take a performance snapshot
*/
async takeSnapshot() {
const aiProcessor = AIProcessor.getInstance();
const metrics = aiProcessor.getPerformanceMetrics();
const snapshot = {
timestamp: Date.now(),
memoryUsage: process.memoryUsage(),
responseMetrics: metrics.responseMetrics,
circuitBreakers: metrics.circuitBreakers,
clientHealth: metrics.clientHealth
};
this.snapshots.push(snapshot);
await this.saveSnapshot(snapshot);
}
/**
* Save snapshot to disk
*/
async saveSnapshot(snapshot) {
await fs.mkdir(this.metricsPath, { recursive: true });
const filename = path.join(this.metricsPath, `snapshot-${snapshot.timestamp}.json`);
await fs.writeFile(filename, JSON.stringify(snapshot, null, 2));
}
/**
* Generate performance report
*/
async generateReport() {
if (this.snapshots.length === 0) {
return 'No performance data available.';
}
const firstSnapshot = this.snapshots[0];
const lastSnapshot = this.snapshots[this.snapshots.length - 1];
// Calculate memory improvements
const memoryImprovement = {
heapUsed: (firstSnapshot.memoryUsage.heapUsed - lastSnapshot.memoryUsage.heapUsed) / 1024 / 1024,
heapTotal: (firstSnapshot.memoryUsage.heapTotal - lastSnapshot.memoryUsage.heapTotal) / 1024 / 1024,
rss: (firstSnapshot.memoryUsage.rss - lastSnapshot.memoryUsage.rss) / 1024 / 1024
};
// Format report
return `
š Migration Performance Report
=============================
Memory Usage Improvements:
------------------------
Heap Used: ${memoryImprovement.heapUsed.toFixed(2)} MB
Heap Total: ${memoryImprovement.heapTotal.toFixed(2)} MB
RSS: ${memoryImprovement.rss.toFixed(2)} MB
Response Time Improvements:
-------------------------
${this.formatResponseMetrics(firstSnapshot, lastSnapshot)}
Health Status:
-------------
Circuit Breakers: ${Object.values(lastSnapshot.circuitBreakers).every(cb => !cb) ? 'ā
Healthy' : 'ā ļø Some Open'}
Client Health: ${Object.values(lastSnapshot.clientHealth).every(h => h === 'healthy') ? 'ā
All Healthy' : 'ā ļø Some Issues'}
`;
}
/**
* Format response metrics comparison
*/
formatResponseMetrics(first, last) {
const metrics = [];
for (const [key, value] of Object.entries(last.responseMetrics)) {
const oldValue = first.responseMetrics[key];
if (typeof oldValue === 'number' && typeof value === 'number') {
const improvement = ((oldValue - value) / oldValue) * 100;
metrics.push(`${key}: ${improvement.toFixed(1)}% faster`);
}
}
return metrics.join('\n');
}
}
export const migrationMonitor = new MigrationMonitor();
//# sourceMappingURL=migrationMonitor.js.map