brainy/.recovery-workspace/dist-backup-20250910-141917/distributed/healthMonitor.d.ts
David Snelling 8ff382ca3b chore: recovery checkpoint - v3.0 API successfully recovered
CRITICAL CHECKPOINT - DO NOT PUSH TO GITHUB

Recovery Status:
- Successfully recovered brainy.ts from compiled JavaScript
- All core v3.0 API methods functional (add, get, update, delete, relate, find, etc.)
- Neural subsystem intact (562KB embedded patterns, NLP working)
- Augmentation pipeline operational (20+ augmentations)
- HNSW clustering system complete
- Triple Intelligence compiled (needs constructor fix)
- Test suite validates functionality

Changes preserved:
- 898 files with changes from last 3 days
- 144,475 insertions
- All augmentation improvements
- All test coverage enhancements
- Complete v3.0 feature set

This is a LOCAL checkpoint only - contains recovered work after corruption incident.
Created backup in .backups/brainy-full-20250910-151314.tar.gz

Branch: recovery-checkpoint-20250910-151433
Date: Wed Sep 10 03:18:04 PM PDT 2025
2025-09-10 15:18:04 -07:00

110 lines
2.6 KiB
TypeScript

/**
* Health Monitor
* Monitors and reports instance health in distributed deployments
*/
import { DistributedConfigManager } from './configManager.js';
export interface HealthMetrics {
vectorCount: number;
cacheHitRate: number;
memoryUsage: number;
cpuUsage?: number;
requestsPerSecond?: number;
averageLatency?: number;
errorRate?: number;
}
export interface HealthStatus {
status: 'healthy' | 'degraded' | 'unhealthy';
instanceId: string;
role: string;
uptime: number;
lastCheck: string;
metrics: HealthMetrics;
warnings?: string[];
errors?: string[];
}
export declare class HealthMonitor {
private configManager;
private startTime;
private requestCount;
private errorCount;
private totalLatency;
private cacheHits;
private cacheMisses;
private vectorCount;
private checkInterval;
private healthCheckTimer?;
private metricsWindow;
private latencyWindow;
private windowSize;
constructor(configManager: DistributedConfigManager);
/**
* Start health monitoring
*/
start(): void;
/**
* Stop health monitoring
*/
stop(): void;
/**
* Update health status and metrics
*/
private updateHealth;
/**
* Collect current metrics
*/
private collectMetrics;
/**
* Calculate cache hit rate
*/
private calculateCacheHitRate;
/**
* Calculate requests per second
*/
private calculateRPS;
/**
* Calculate average latency
*/
private calculateAverageLatency;
/**
* Calculate error rate
*/
private calculateErrorRate;
/**
* Get CPU usage (simplified)
*/
private getCPUUsage;
/**
* Clean old entries from sliding windows
*/
private cleanWindows;
/**
* Record a request
* @param latency - Request latency in milliseconds
* @param error - Whether the request resulted in an error
*/
recordRequest(latency: number, error?: boolean): void;
/**
* Record cache access
* @param hit - Whether it was a cache hit
*/
recordCacheAccess(hit: boolean): void;
/**
* Update vector count
* @param count - New vector count
*/
updateVectorCount(count: number): void;
/**
* Get current health status
* @returns Health status object
*/
getHealthStatus(): HealthStatus;
/**
* Get health check endpoint data
* @returns JSON-serializable health data
*/
getHealthEndpointData(): Record<string, any>;
/**
* Reset metrics (useful for testing)
*/
resetMetrics(): void;
}