optivise
Version:
Optivise - The Ultimate Optimizely Development Assistant with AI-powered features, zero-config setup, and comprehensive development support
193 lines • 4.87 kB
TypeScript
/**
* Comprehensive Monitoring and Analytics Service
* Tracks performance, usage patterns, and system health with real-time analytics
*/
import { EventEmitter } from 'events';
import type { Logger, OptimizelyProduct } from '../types/index.js';
export interface PerformanceMetric {
operation: string;
duration: number;
timestamp: number;
success: boolean;
metadata?: Record<string, any>;
}
export interface UsageMetric {
tool: string;
feature: string;
user?: string;
timestamp: number;
context?: Record<string, any>;
}
export interface SystemMetric {
metric: string;
value: number;
unit: string;
timestamp: number;
tags?: Record<string, string>;
}
export interface AlertRule {
id: string;
name: string;
condition: (metrics: SystemMetric[]) => boolean;
severity: 'low' | 'medium' | 'high' | 'critical';
enabled: boolean;
cooldown: number;
lastTriggered?: number;
}
export interface AnalyticsReport {
timeframe: {
start: number;
end: number;
};
performance: {
avgResponseTime: number;
operationsPerSecond: number;
errorRate: number;
slowestOperations: Array<{
operation: string;
avgDuration: number;
}>;
};
usage: {
totalRequests: number;
uniqueUsers: number;
topTools: Array<{
tool: string;
usage: number;
}>;
topFeatures: Array<{
feature: string;
usage: number;
}>;
productDistribution: Record<OptimizelyProduct, number>;
};
system: {
memoryUsage: number;
cpuUsage: number;
cacheHitRate: number;
aiServiceUptime: number;
};
trends: {
hourlyUsage: number[];
dailyGrowth: number;
performanceTrend: 'improving' | 'stable' | 'declining';
};
}
export declare class MonitoringService extends EventEmitter {
private performanceMetrics;
private usageMetrics;
private systemMetrics;
private alertRules;
private activeAlerts;
private logger;
private metricsRetentionMs;
private cleanupInterval?;
constructor(logger: Logger, retentionHours?: number);
/**
* Record performance metric
*/
recordPerformance(metric: Omit<PerformanceMetric, 'timestamp'>): void;
/**
* Record usage metric
*/
recordUsage(metric: Omit<UsageMetric, 'timestamp'>): void;
/**
* Record system metric
*/
recordSystem(metric: Omit<SystemMetric, 'timestamp'>): void;
/**
* Start timing a performance operation
*/
startTimer(operation: string, metadata?: Record<string, any>): () => void;
/**
* Decorator for timing async operations
*/
timeAsync<T>(operation: string, metadata?: Record<string, any>): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
/**
* Add or update alert rule
*/
addAlertRule(rule: AlertRule): void;
/**
* Remove alert rule
*/
removeAlertRule(id: string): boolean;
/**
* Get all alert rules
*/
getAlertRules(): AlertRule[];
/**
* Get active alerts
*/
getActiveAlerts(): string[];
/**
* Generate comprehensive analytics report
*/
generateReport(timeframeHours?: number): AnalyticsReport;
/**
* Get real-time system status
*/
getSystemStatus(): {
status: 'healthy' | 'warning' | 'critical';
uptime: number;
activeAlerts: number;
recentErrors: number;
performance: {
avgResponseTime: number;
throughput: number;
};
};
/**
* Export metrics for external analysis
*/
exportMetrics(format?: 'json' | 'csv'): string;
/**
* Setup default alert rules
*/
private setupDefaultAlerts;
/**
* Check performance alerts
*/
private checkPerformanceAlerts;
/**
* Check system alerts
*/
private checkSystemAlerts;
/**
* Trigger an alert
*/
private triggerAlert;
/**
* Resolve an alert
*/
private resolveAlert;
/**
* Analyze performance metrics
*/
private analyzePerformance;
/**
* Analyze usage metrics
*/
private analyzeUsage;
/**
* Analyze system metrics
*/
private analyzeSystem;
/**
* Analyze trends
*/
private analyzeTrends;
/**
* Start cleanup timer to remove old metrics
*/
private startCleanupTimer;
/**
* Remove old metrics beyond retention period
*/
private cleanupOldMetrics;
/**
* Cleanup resources
*/
destroy(): void;
}
export declare const monitoringService: (logger: Logger) => MonitoringService;
//# sourceMappingURL=monitoring-service.d.ts.map