UNPKG

@varia-bly/variably-sdk

Version:

Official JavaScript/TypeScript SDK for Variably feature flags, experimentation, LLM experiments with React hooks, and real-time dynamic configurations

170 lines 4.1 kB
/** * Real-time alerting system for metric thresholds * Implements future enhancement features from the metrics collection documentation */ export interface MetricThreshold { id: string; name: string; metricName: string; operator: 'gt' | 'lt' | 'gte' | 'lte' | 'eq' | 'neq'; threshold: number; timeWindow: number; evaluationInterval: number; severity: 'info' | 'warning' | 'critical'; enabled: boolean; cooldownPeriod?: number; } export interface MetricAlert { id: string; thresholdId: string; metricName: string; currentValue: number; thresholdValue: number; operator: string; severity: 'info' | 'warning' | 'critical'; triggeredAt: Date; message: string; context?: Record<string, any>; } export interface AlertChannel { type: 'webhook' | 'email' | 'slack' | 'console'; config: WebhookConfig | EmailConfig | SlackConfig | ConsoleConfig; enabled: boolean; } export interface WebhookConfig { url: string; method: 'POST' | 'PUT'; headers?: Record<string, string>; retryAttempts?: number; } export interface EmailConfig { recipients: string[]; subject?: string; template?: string; } export interface SlackConfig { webhookUrl: string; channel: string; username?: string; iconEmoji?: string; } export interface ConsoleConfig { logLevel: 'info' | 'warn' | 'error'; } export interface MetricDataPoint { metricName: string; value: number; timestamp: Date; context?: Record<string, any>; } export declare class RealTimeAlerting { private thresholds; private channels; private metricData; private alertHistory; private timers; private cooldownTracker; /** * Add a metric threshold for monitoring */ addThreshold(threshold: MetricThreshold): void; /** * Remove a metric threshold */ removeThreshold(thresholdId: string): void; /** * Update a metric threshold */ updateThreshold(threshold: MetricThreshold): void; /** * Add an alert channel */ addChannel(channel: AlertChannel): void; /** * Remove an alert channel */ removeChannel(channelType: string): void; /** * Record a metric data point */ recordMetric(dataPoint: MetricDataPoint): void; /** * Get alert history */ getAlertHistory(hours?: number): MetricAlert[]; /** * Get current metric value */ getCurrentMetricValue(metricName: string): number | undefined; /** * Get metric statistics over time window */ getMetricStats(metricName: string, timeWindow: number): { avg: number; min: number; max: number; count: number; trend: 'up' | 'down' | 'stable'; } | undefined; /** * Destroy the alerting system and clean up resources */ destroy(): void; /** * Start monitoring a threshold */ private startMonitoring; /** * Stop monitoring a threshold */ private stopMonitoring; /** * Check thresholds immediately for a specific metric */ private checkThresholdsForMetric; /** * Evaluate a single threshold */ private evaluateThreshold; /** * Check if threshold is breached */ private checkThresholdBreach; /** * Check if threshold is in cooldown period */ private isInCooldown; /** * Trigger an alert */ private triggerAlert; /** * Format alert message */ private formatAlertMessage; /** * Get human-readable operator text */ private getOperatorText; /** * Send alert through all configured channels */ private sendAlertThroughChannels; /** * Send alert to specific channel */ private sendAlertToChannel; /** * Send console alert */ private sendConsoleAlert; /** * Send webhook alert */ private sendWebhookAlert; /** * Send Slack alert */ private sendSlackAlert; } //# sourceMappingURL=alerting.d.ts.map