UNPKG

recoder-analytics

Version:

Comprehensive analytics and monitoring for the Recoder.xyz ecosystem

179 lines 4.76 kB
/** * Alert Management & Orchestration System * * Central alert management with intelligent routing, deduplication, * escalation policies, and multi-channel notifications. */ import { EventEmitter } from 'events'; export interface Alert { id: string; type: AlertType; severity: AlertSeverity; title: string; message: string; source: string; modelName?: string; provider?: string; timestamp: Date; data?: Record<string, any>; tags: string[]; fingerprint: string; resolvedAt?: Date; resolvedBy?: string; resolutionNote?: string; acknowledged: boolean; acknowledgedBy?: string; acknowledgedAt?: Date; suppressedUntil?: Date; } export declare enum AlertType { AVAILABILITY = "availability", LATENCY = "latency", ERROR_RATE = "error_rate", COST = "cost", BUDGET = "budget", PREDICTIVE = "predictive", CIRCUIT_BREAKER = "circuit_breaker", HEALTH_DEGRADATION = "health_degradation", PATTERN_DETECTION = "pattern_detection", SYSTEM = "system" } export declare enum AlertSeverity { LOW = "low", MEDIUM = "medium", HIGH = "high", CRITICAL = "critical" } export interface AlertRule { id: string; name: string; description: string; type: AlertType; severity: AlertSeverity; enabled: boolean; conditions: AlertCondition[]; suppressions: AlertSuppression[]; escalationPolicyId?: string; notificationChannels: string[]; tags: string[]; createdAt: Date; updatedAt: Date; } export interface AlertCondition { metric: string; operator: 'gt' | 'lt' | 'eq' | 'gte' | 'lte' | 'contains' | 'matches'; threshold: number | string; duration: number; aggregation?: 'avg' | 'sum' | 'max' | 'min' | 'count'; } export interface AlertSuppression { type: 'time_window' | 'dependency' | 'maintenance' | 'manual'; startTime?: Date; endTime?: Date; dependsOn?: string[]; reason?: string; } export interface AlertStatistics { total: number; byType: Record<AlertType, number>; bySeverity: Record<AlertSeverity, number>; resolved: number; acknowledged: number; avgResolutionTime: number; timeframe: string; topSources: Array<{ source: string; count: number; }>; } export declare class AlertManager extends EventEmitter { private alerts; private alertRules; private alertHistory; private notificationService; private escalationPolicies; private config; private escalationTimer; private isRunning; constructor(); private initializeDefaultRules; /** * Start alert management system */ start(): Promise<void>; /** * Stop alert management system */ stop(): Promise<void>; /** * Process an incoming alert */ processAlert(alertData: { type: AlertType; severity: AlertSeverity; title?: string; message: string; source: string; modelName?: string; provider?: string; data?: Record<string, any>; tags?: string[]; }): Promise<string>; /** * Acknowledge an alert */ acknowledgeAlert(alertId: string, acknowledgedBy: string, note?: string): Promise<void>; /** * Resolve an alert */ resolveAlert(alertId: string, resolvedBy: string, note?: string): Promise<void>; /** * Suppress alerts matching criteria */ suppressAlerts(criteria: { type?: AlertType; severity?: AlertSeverity; source?: string; modelName?: string; tags?: string[]; }, suppressionOptions: { duration?: number; reason: string; suppressedBy: string; }): Promise<number>; /** * Get active alerts with optional filtering */ getActiveAlerts(filters?: { type?: AlertType; severity?: AlertSeverity; source?: string; acknowledged?: boolean; }): Alert[]; /** * Get alert statistics */ getAlertStatistics(timeframe?: string): AlertStatistics; /** * Create or update an alert rule */ setAlertRule(rule: AlertRule): Promise<void>; /** * Get all alert rules */ getAlertRules(): AlertRule[]; private generateFingerprint; private findExistingAlert; private shouldCreateNewAlert; private generateTitle; private shouldSendNotification; private sendNotifications; private sendResolutionNotification; private startEscalation; private checkEscalations; private alertMatchesCriteria; private getTimeframeCutoff; private cleanupOldAlerts; } export declare const alertManager: AlertManager; //# sourceMappingURL=alert-manager.d.ts.map