@ahmedhegazee/nestjs-telescope
Version:
Advanced observability and monitoring solution for NestJS applications with ML-powered analytics, enterprise features, and production-ready scaling
147 lines (146 loc) • 4.53 kB
TypeScript
import { OnModuleInit, OnModuleDestroy } from '@nestjs/common';
import { Observable } from 'rxjs';
import { MLAnalyticsService, MLAlert } from './ml-analytics.service';
import { AnalyticsService } from './analytics.service';
import { MemoryManagerService } from './memory-manager.service';
export interface AlertChannel {
id: string;
name: string;
type: 'email' | 'slack' | 'teams' | 'webhook' | 'sms' | 'pagerduty';
enabled: boolean;
config: {
url?: string;
token?: string;
email?: string;
phone?: string;
[key: string]: any;
};
severityFilter: ('info' | 'warning' | 'error' | 'critical')[];
componentFilter?: string[];
rateLimit?: {
maxAlerts: number;
timeWindow: number;
};
}
export interface AlertRule {
id: string;
name: string;
description: string;
enabled: boolean;
priority: number;
conditions: {
metric: string;
operator: '>' | '<' | '==' | '!=' | '>=' | '<=';
threshold: number;
duration?: number;
component?: string;
}[];
actions: {
channelIds: string[];
escalation?: {
delayMinutes: number;
channels: string[];
};
autoRemediation?: {
enabled: boolean;
actions: Array<{
type: 'restart' | 'scale' | 'rollback' | 'cache_clear';
config: any;
}>;
};
};
schedule?: {
timezone: string;
activeHours: {
start: string;
end: string;
};
activeDays: number[];
};
}
export interface AlertHistory {
id: string;
alertId: string;
ruleId: string | undefined;
timestamp: Date;
status: 'sent' | 'failed' | 'acknowledged' | 'resolved';
channel: string;
recipient: string | undefined;
retryCount: number;
error: string | undefined;
responseTime: number | undefined;
}
export interface AlertAggregation {
id: string;
timestamp: Date;
timeWindow: number;
component: string;
alertCount: number;
severity: 'info' | 'warning' | 'error' | 'critical';
types: string[];
summary: string;
consolidatedAlert: MLAlert;
}
export interface AlertMetrics {
totalAlerts: number;
alertsBySeverity: Record<string, number>;
alertsByComponent: Record<string, number>;
alertsByChannel: Record<string, number>;
averageResponseTime: number;
successRate: number;
escalationRate: number;
acknowledgedRate: number;
falsePositiveRate: number;
}
export declare class AutomatedAlertingService implements OnModuleInit, OnModuleDestroy {
private readonly mlAnalyticsService;
private readonly analyticsService;
private readonly memoryManager;
private readonly logger;
private subscriptions;
private alertChannels;
private alertRules;
private rateLimitTracker;
private readonly collectionIds;
private readonly alertHistorySubject;
private readonly aggregationSubject;
private alertHistory;
private readonly config;
constructor(mlAnalyticsService: MLAnalyticsService, analyticsService: AnalyticsService, memoryManager: MemoryManagerService);
onModuleInit(): Promise<void>;
onModuleDestroy(): void;
private initializeDefaultChannels;
private initializeDefaultRules;
private startAlertProcessing;
private processAlert;
private processAnomalyAlert;
private processRegressionAlert;
private processPredictiveAlert;
private findMatchingRules;
private executeAlertRule;
private executeDefaultAlert;
private sendAlert;
private sendWebhookAlert;
private sendEmailAlert;
private sendSlackAlert;
private retryAlert;
private escalateAlert;
private executeAutoRemediation;
private isRateLimited;
private isWithinSchedule;
private parseTime;
private cleanupOldHistory;
private processAlertAggregation;
private autoAcknowledgeOldAlerts;
addAlertChannel(channel: AlertChannel): void;
removeAlertChannel(channelId: string): boolean;
addAlertRule(rule: AlertRule): void;
removeAlertRule(ruleId: string): boolean;
getAlertChannels(): AlertChannel[];
getAlertRules(): AlertRule[];
getAlertHistory(limit?: number): AlertHistory[];
getAlertHistoryStream(): Observable<AlertHistory>;
acknowledgeAlert(alertId: string): boolean;
getAlertMetrics(): AlertMetrics;
testAlertChannel(channelId: string): Promise<boolean>;
}