UNPKG

@push.rocks/smartproxy

Version:

A powerful proxy package with unified route-based configuration for high traffic management. Features include SSL/TLS support, flexible routing patterns, WebSocket handling, advanced security options, and automatic ACME certificate management.

95 lines (94 loc) 2.75 kB
import type { SmartProxy } from './smart-proxy.js'; import type { IMetrics, IThroughputData, IThroughputHistoryPoint } from './models/metrics-types.js'; /** * Collects and provides metrics for SmartProxy with clean API */ export declare class MetricsCollector implements IMetrics { private smartProxy; private throughputTracker; private routeThroughputTrackers; private ipThroughputTrackers; private requestTimestamps; private totalRequests; private connectionByteTrackers; private samplingInterval?; private connectionSubscription?; private readonly sampleIntervalMs; private readonly retentionSeconds; constructor(smartProxy: SmartProxy, config?: { sampleIntervalMs?: number; retentionSeconds?: number; }); connections: { active: () => number; total: () => number; byRoute: () => Map<string, number>; byIP: () => Map<string, number>; topIPs: (limit?: number) => Array<{ ip: string; count: number; }>; }; throughput: { instant: () => IThroughputData; recent: () => IThroughputData; average: () => IThroughputData; custom: (seconds: number) => IThroughputData; history: (seconds: number) => Array<IThroughputHistoryPoint>; byRoute: (windowSeconds?: number) => Map<string, IThroughputData>; byIP: (windowSeconds?: number) => Map<string, IThroughputData>; }; requests: { perSecond: () => number; perMinute: () => number; total: () => number; }; totals: { bytesIn: () => number; bytesOut: () => number; connections: () => number; }; percentiles: { connectionDuration: () => { p50: number; p95: number; p99: number; }; bytesTransferred: () => { in: { p50: number; p95: number; p99: number; }; out: { p50: number; p95: number; p99: number; }; }; }; /** * Record a new request */ recordRequest(connectionId: string, routeName: string, remoteIP: string): void; /** * Record bytes transferred for a connection */ recordBytes(connectionId: string, bytesIn: number, bytesOut: number): void; /** * Clean up tracking for a closed connection */ removeConnection(connectionId: string): void; /** * Start the metrics collector */ start(): void; /** * Stop the metrics collector */ stop(): void; /** * Alias for stop() for compatibility */ destroy(): void; }