/** * Health Monitor * * System resource tracking, performance monitoring, and self-healing * using MPC (Message Passing with Coordination) algorithm. */ import { EventEmitter } from 'events'; export interface HealthMetrics { timestamp: Date; cpu: { usage: number; loadAverage: number[]; cores: number; }; memory: { used: number; available: number; heapUsed: number; heapTotal: number; rss: number; external: number; }; disk?: { readMBps: number; writeMBps: number; }; simulation?: { iterationsCompleted: number; itemsProcessed: number; errorsEncountered: number; progressPercent: number; }; } export interface Alert { level: 'info' | 'warning' | 'critical'; metric: string; threshold: number; actual: number; timestamp: Date; action: 'log' | 'throttle' | 'abort' | 'heal'; message: string; } export interface AlertThresholds { memoryMB: number; latencyMs: number; cpuPercent?: number; errorRate?: number; } export interface HealingAction { type: 'reduce_batch_size' | 'pause_and_gc' | 'restart_component' | 'abort'; reason: string; parameters?: Record; } export declare class HealthMonitor extends EventEmitter { private monitoringInterval; private intervalMs; private thresholds; private baselineMetrics; private metricsHistory; private maxHistorySize; constructor(thresholds: AlertThresholds); /** * Start monitoring system resources. */ startMonitoring(intervalMs?: number): void; /** * Stop monitoring. */ stopMonitoring(): void; /** * Collect current system metrics. */ collectMetrics(): HealthMetrics; /** * Get CPU usage percentage. */ private getCPUUsage; /** * Check metrics against thresholds. */ private checkThresholds; /** * Detect memory leaks by analyzing growth trend. */ private detectMemoryLeak; /** * Check if memory is consistently growing. */ private isConsistentGrowth; /** * Trigger self-healing using MPC coordination. * * MPC (Message Passing with Coordination) achieved 97.9% recall in simulations. * We use it here for automatic recovery by coordinating between components. */ private triggerSelfHealing; /** * Select healing strategy using MPC-inspired coordination. * * MPC coordinates between nodes to find stable state. Here, we coordinate * between different recovery strategies based on alert severity and history. */ private selectHealingStrategy; /** * Check if garbage collection can recover memory. */ private canRecoverWithGC; /** * Get recent alerts (last 10 seconds). */ private getRecentAlerts; /** * Heal by forcing garbage collection. */ private healByGarbageCollection; /** * Heal by reducing workload. */ private healByReducingLoad; /** * Heal by restarting component. */ private healByRestartingComponent; /** * Heal by aborting (last resort). */ private healByAborting; /** * Get current health status. */ getStatus(): { healthy: boolean; metrics: HealthMetrics; alerts: Alert[]; }; /** * Get metrics history. */ getHistory(): HealthMetrics[]; /** * Generate health report. */ generateReport(): string; } /** * Create health monitor instance. */ export declare function createHealthMonitor(thresholds: AlertThresholds): HealthMonitor; //# sourceMappingURL=health-monitor.d.ts.map