/** * Metrics Collector Utility * * Comprehensive metrics collection system for performance monitoring. * Supports counters, gauges, histograms, and timers with automatic aggregation. */ export interface CounterMetric { description: string; labels?: Record; name: string; value: number; } export interface GaugeMetric { description: string; labels?: Record; name: string; value: number; } export interface HistogramMetric { buckets: Record; count: number; description: string; labels?: Record; name: string; sum: number; } export interface MetricsOptions { cleanupInterval?: number; enableHistograms?: boolean; histogramBuckets?: number[]; maxMetricsAge?: number; } export interface MetricsSnapshot { collectionDuration: number; counters: CounterMetric[]; gauges: GaugeMetric[]; histograms: HistogramMetric[]; timestamp: number; uptime: number; } export interface MetricValue { labels?: Record; timestamp: number; value: number; } export interface TimerResult { duration: number; endTime: number; startTime: number; } /** * Metrics Collector Class * * Provides comprehensive metrics collection with automatic cleanup and aggregation. */ export declare class MetricsCollector { private cleanupInterval; private counters; private gauges; private histograms; private options; private startTime; private timers; constructor(options?: MetricsOptions); /** * Increment a counter metric */ incrementCounter(name: string, value?: number, labels?: Record): void; /** * Set a gauge metric value */ setGauge(name: string, value: number, labels?: Record): void; /** * Update a gauge metric by adding to current value */ updateGauge(name: string, delta: number, labels?: Record): void; /** * Record a histogram observation */ observeHistogram(name: string, value: number, labels?: Record): void; /** * Start a timer for measuring operation duration */ startTimer(name: string): string; /** * End a timer and record the duration */ endTimer(timerId: string, labels?: Record): null | TimerResult; /** * Time an async operation automatically */ timeAsync(name: string, operation: () => Promise, labels?: Record): Promise; /** * Time a sync operation automatically */ timeSync(name: string, operation: () => T, labels?: Record): T; /** * Get a snapshot of all current metrics */ getSnapshot(): MetricsSnapshot; /** * Export metrics in Prometheus format */ exportPrometheus(): string; /** * Reset all metrics */ reset(): void; /** * Get metrics statistics */ getStats(): { activeTimers: number; counters: number; gauges: number; histograms: number; uptime: number; }; /** * Destroy the collector and clean up resources */ destroy(): void; /** * Create a unique key for metrics with labels */ private createKey; /** * Convert metric name to Prometheus format */ private prometheusName; /** * Format labels for Prometheus */ private formatPrometheusLabels; /** * Start automatic cleanup of old metrics */ private startCleanup; /** * Clean up old metrics based on age and activity */ private cleanup; } /** * Get the global metrics collector instance */ export declare function getMetricsCollector(options?: MetricsOptions): MetricsCollector; /** * Set a custom global metrics collector instance */ export declare function setMetricsCollector(collector: MetricsCollector): void; /** * Convenience functions for global metrics collection */ export declare function endTimer(timerId: string, labels?: Record): null | TimerResult; export declare function exportMetricsPrometheus(): string; export declare function getMetricsSnapshot(): MetricsSnapshot; export declare function incrementCounter(name: string, value?: number, labels?: Record): void; export declare function observeHistogram(name: string, value: number, labels?: Record): void; export declare function setGauge(name: string, value: number, labels?: Record): void; export declare function startTimer(name: string): string; export declare function timeAsync(name: string, operation: () => Promise, labels?: Record): Promise; export declare function timeSync(name: string, operation: () => T, labels?: Record): T; export declare function updateGauge(name: string, delta: number, labels?: Record): void; //# sourceMappingURL=metrics-collector.d.ts.map