/**
 * Metrics Collector
 *
 * Centralized metrics collection system for Code Buddy.
 * Supports counters, gauges, histograms, and various exporters.
 *
 * Features:
 * - Counters: Track cumulative values (requests, errors, tokens)
 * - Gauges: Track current values (memory, connections)
 * - Histograms: Track distributions (latency, execution time)
 * - Multiple exporters: Console, File, OpenTelemetry
 */
import { EventEmitter } from 'events';
export interface MetricLabels {
    [key: string]: string;
}
export interface CounterValue {
    value: number;
    labels: MetricLabels;
}
export interface GaugeValue {
    value: number;
    labels: MetricLabels;
    timestamp: number;
}
export interface HistogramValue {
    count: number;
    sum: number;
    min: number;
    max: number;
    buckets: Map<number, number>;
    labels: MetricLabels;
}
export interface MetricDefinition {
    name: string;
    help: string;
    type: 'counter' | 'gauge' | 'histogram';
    unit?: string;
}
export interface MetricsSnapshot {
    timestamp: number;
    counters: Record<string, CounterValue[]>;
    gauges: Record<string, GaugeValue[]>;
    histograms: Record<string, HistogramValue[]>;
    system: SystemMetrics;
}
export interface SystemMetrics {
    memory: {
        heapUsed: number;
        heapTotal: number;
        external: number;
        rss: number;
        arrayBuffers: number;
    };
    cpu: {
        user: number;
        system: number;
    };
    uptime: number;
    activeHandles: number;
    activeRequests: number;
}
export interface MetricsConfig {
    /** Enable console export (debug mode) */
    consoleExport?: boolean;
    /** Enable file export */
    fileExport?: boolean;
    /** File export path */
    filePath?: string;
    /** Export interval in milliseconds */
    exportInterval?: number;
    /** Enable OpenTelemetry export */
    otelExport?: boolean;
    /** Default histogram buckets */
    defaultBuckets?: number[];
    /** Max metrics history size */
    maxHistorySize?: number;
}
/**
 * Counter metric - monotonically increasing value
 */
export declare class Counter {
    readonly name: string;
    readonly help: string;
    readonly unit?: string | undefined;
    private values;
    constructor(name: string, help: string, unit?: string | undefined);
    /**
     * Increment counter
     */
    inc(labels?: MetricLabels, value?: number): void;
    /**
     * Get all values
     */
    getValues(): CounterValue[];
    /**
     * Reset counter
     */
    reset(): void;
    private labelsToKey;
    private keyToLabels;
}
/**
 * Gauge metric - value that can go up and down
 */
export declare class Gauge {
    readonly name: string;
    readonly help: string;
    readonly unit?: string | undefined;
    private values;
    private timestamps;
    constructor(name: string, help: string, unit?: string | undefined);
    /**
     * Set gauge value
     */
    set(value: number, labels?: MetricLabels): void;
    /**
     * Increment gauge
     */
    inc(labels?: MetricLabels, value?: number): void;
    /**
     * Decrement gauge
     */
    dec(labels?: MetricLabels, value?: number): void;
    /**
     * Get all values
     */
    getValues(): GaugeValue[];
    /**
     * Reset gauge
     */
    reset(): void;
    private labelsToKey;
    private keyToLabels;
}
/**
 * Histogram metric - distribution of values
 */
export declare class Histogram {
    readonly name: string;
    readonly help: string;
    readonly buckets: number[];
    readonly unit?: string | undefined;
    private values;
    constructor(name: string, help: string, buckets?: number[], unit?: string | undefined);
    /**
     * Observe a value
     */
    observe(value: number, labels?: MetricLabels): void;
    /**
     * Get all values
     */
    getValues(): HistogramValue[];
    /**
     * Start a timer
     */
    startTimer(labels?: MetricLabels): () => number;
    /**
     * Reset histogram
     */
    reset(): void;
    private labelsToKey;
    private keyToLabels;
}
/**
 * Main metrics collector class
 */
export declare class MetricsCollector extends EventEmitter {
    private config;
    private counters;
    private gauges;
    private histograms;
    private exportInterval;
    private startTime;
    private history;
    private initialized;
    readonly requestsTotal: Counter;
    readonly requestErrors: Counter;
    readonly tokensUsed: Counter;
    readonly toolExecutions: Counter;
    readonly apiLatency: Histogram;
    readonly toolDuration: Histogram;
    readonly memoryUsage: Gauge;
    readonly activeConnections: Gauge;
    readonly activeSessions: Gauge;
    constructor(config?: MetricsConfig);
    /**
     * Initialize metrics collector
     */
    init(): Promise<void>;
    /**
     * Create a counter metric
     */
    createCounter(name: string, help: string, unit?: string): Counter;
    /**
     * Create a gauge metric
     */
    createGauge(name: string, help: string, unit?: string): Gauge;
    /**
     * Create a histogram metric
     */
    createHistogram(name: string, help: string, buckets?: number[], unit?: string): Histogram;
    /**
     * Get a counter by name
     */
    getCounter(name: string): Counter | undefined;
    /**
     * Get a gauge by name
     */
    getGauge(name: string): Gauge | undefined;
    /**
     * Get a histogram by name
     */
    getHistogram(name: string): Histogram | undefined;
    /**
     * Collect system metrics
     */
    private collectSystemMetrics;
    /**
     * Get system metrics
     */
    getSystemMetrics(): SystemMetrics;
    /**
     * Get current metrics snapshot
     */
    getSnapshot(): MetricsSnapshot;
    /**
     * Export metrics in Prometheus format
     */
    toPrometheus(): string;
    /**
     * Export metrics in JSON format
     */
    toJSON(): MetricsSnapshot;
    /**
     * Format labels for Prometheus
     */
    private formatLabels;
    /**
     * Export metrics to configured destinations
     */
    export(): Promise<void>;
    /**
     * Export metrics to file
     */
    private exportToFile;
    /**
     * Get metrics history
     */
    getHistory(limit?: number): MetricsSnapshot[];
    /**
     * Reset all metrics
     */
    reset(): void;
    /**
     * Shutdown metrics collector
     */
    shutdown(): Promise<void>;
}
/**
 * Initialize metrics collector
 */
export declare function initMetrics(config?: MetricsConfig): MetricsCollector;
/**
 * Get metrics collector instance
 */
export declare function getMetrics(): MetricsCollector | null;
/**
 * Helper: Measure function execution time
 */
export declare function measureTime<T>(histogramName: string, labels: MetricLabels, fn: () => Promise<T>): Promise<T>;
/**
 * Helper: Increment counter
 */
export declare function incCounter(name: string, labels?: MetricLabels, value?: number): void;
/**
 * Helper: Set gauge value
 */
export declare function setGauge(name: string, value: number, labels?: MetricLabels): void;
export default MetricsCollector;
