@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.
99 lines (98 loc) • 3.31 kB
TypeScript
import type { IMetrics, IBackendMetrics, IProtocolCacheEntry, IProtocolDistribution, IRequestRateMetrics, IThroughputData, IThroughputHistoryPoint } from './models/metrics-types.js';
import type { RustProxyBridge } from './rust-proxy-bridge.js';
/**
* Adapts Rust JSON metrics to the IMetrics interface.
*
* Polls the Rust binary periodically via the bridge and caches the result.
* All IMetrics getters read from the cache synchronously.
*
* Rust Metrics JSON fields (camelCase via serde):
* activeConnections, totalConnections, bytesIn, bytesOut,
* throughputInBytesPerSec, throughputOutBytesPerSec,
* routes: { [routeName]: { activeConnections, totalConnections, bytesIn, bytesOut, ... } }
*/
export declare class RustMetricsAdapter implements IMetrics {
private bridge;
private cache;
private pollTimer;
private pollIntervalMs;
constructor(bridge: RustProxyBridge, pollIntervalMs?: number);
/**
* Poll Rust for metrics once. Can be awaited to ensure cache is fresh.
*/
poll(): Promise<void>;
startPolling(): void;
stopPolling(): void;
connections: {
active: () => number;
total: () => number;
byRoute: () => Map<string, number>;
byIP: () => Map<string, number>;
topIPs: (limit?: number) => Array<{
ip: string;
count: number;
}>;
domainRequestsByIP: () => Map<string, Map<string, number>>;
topDomainRequests: (limit?: number) => Array<{
ip: string;
domain: string;
count: number;
}>;
frontendProtocols: () => IProtocolDistribution;
backendProtocols: () => IProtocolDistribution;
};
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;
byDomain: () => Map<string, IRequestRateMetrics>;
};
totals: {
bytesIn: () => number;
bytesOut: () => number;
connections: () => number;
};
backends: {
byBackend: () => Map<string, IBackendMetrics>;
protocols: () => Map<string, string>;
topByErrors: (limit?: number) => Array<{
backend: string;
errors: number;
}>;
detectedProtocols: () => IProtocolCacheEntry[];
};
udp: {
activeSessions: () => number;
totalSessions: () => number;
datagramsIn: () => number;
datagramsOut: () => number;
};
percentiles: {
connectionDuration: () => {
p50: number;
p95: number;
p99: number;
};
bytesTransferred: () => {
in: {
p50: number;
p95: number;
p99: number;
};
out: {
p50: number;
p95: number;
p99: number;
};
};
};
}