feat(metrics): add frontend and backend protocol distribution metrics
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartproxy',
|
||||
version: '27.1.0',
|
||||
version: '27.2.0',
|
||||
description: '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.'
|
||||
}
|
||||
|
||||
@@ -32,6 +32,23 @@ export interface IThroughputHistoryPoint {
|
||||
/**
|
||||
* Main metrics interface with clean, grouped API
|
||||
*/
|
||||
/**
|
||||
* Protocol distribution for frontend (client→proxy) or backend (proxy→upstream).
|
||||
* Tracks active and total counts for h1/h2/h3/ws/other.
|
||||
*/
|
||||
export interface IProtocolDistribution {
|
||||
h1Active: number;
|
||||
h1Total: number;
|
||||
h2Active: number;
|
||||
h2Total: number;
|
||||
h3Active: number;
|
||||
h3Total: number;
|
||||
wsActive: number;
|
||||
wsTotal: number;
|
||||
otherActive: number;
|
||||
otherTotal: number;
|
||||
}
|
||||
|
||||
export interface IMetrics {
|
||||
// Connection metrics
|
||||
connections: {
|
||||
@@ -40,6 +57,8 @@ export interface IMetrics {
|
||||
byRoute(): Map<string, number>;
|
||||
byIP(): Map<string, number>;
|
||||
topIPs(limit?: number): Array<{ ip: string; count: number }>;
|
||||
frontendProtocols(): IProtocolDistribution;
|
||||
backendProtocols(): IProtocolDistribution;
|
||||
};
|
||||
|
||||
// Throughput metrics (bytes per second)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { IMetrics, IBackendMetrics, IProtocolCacheEntry, IThroughputData, IThroughputHistoryPoint } from './models/metrics-types.js';
|
||||
import type { IMetrics, IBackendMetrics, IProtocolCacheEntry, IProtocolDistribution, IThroughputData, IThroughputHistoryPoint } from './models/metrics-types.js';
|
||||
import type { RustProxyBridge } from './rust-proxy-bridge.js';
|
||||
|
||||
/**
|
||||
@@ -90,6 +90,49 @@ export class RustMetricsAdapter implements IMetrics {
|
||||
result.sort((a, b) => b.count - a.count);
|
||||
return result.slice(0, limit);
|
||||
},
|
||||
frontendProtocols: (): IProtocolDistribution => {
|
||||
const fp = this.cache?.frontendProtocols;
|
||||
return {
|
||||
h1Active: fp?.h1Active ?? 0,
|
||||
h1Total: fp?.h1Total ?? 0,
|
||||
h2Active: fp?.h2Active ?? 0,
|
||||
h2Total: fp?.h2Total ?? 0,
|
||||
h3Active: fp?.h3Active ?? 0,
|
||||
h3Total: fp?.h3Total ?? 0,
|
||||
wsActive: fp?.wsActive ?? 0,
|
||||
wsTotal: fp?.wsTotal ?? 0,
|
||||
otherActive: fp?.otherActive ?? 0,
|
||||
otherTotal: fp?.otherTotal ?? 0,
|
||||
};
|
||||
},
|
||||
backendProtocols: (): IProtocolDistribution => {
|
||||
// Merge per-backend h1/h2/h3 data with aggregate ws/other counters
|
||||
const bp = this.cache?.backendProtocols;
|
||||
let h1Active = 0, h1Total = 0;
|
||||
let h2Active = 0, h2Total = 0;
|
||||
let h3Active = 0, h3Total = 0;
|
||||
if (this.cache?.backends) {
|
||||
for (const bm of Object.values(this.cache.backends)) {
|
||||
const m = bm as any;
|
||||
const active = m.activeConnections ?? 0;
|
||||
const total = m.totalConnections ?? 0;
|
||||
switch (m.protocol) {
|
||||
case 'h2': h2Active += active; h2Total += total; break;
|
||||
case 'h3': h3Active += active; h3Total += total; break;
|
||||
default: h1Active += active; h1Total += total; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
h1Active, h1Total,
|
||||
h2Active, h2Total,
|
||||
h3Active, h3Total,
|
||||
wsActive: bp?.wsActive ?? 0,
|
||||
wsTotal: bp?.wsTotal ?? 0,
|
||||
otherActive: bp?.otherActive ?? 0,
|
||||
otherTotal: bp?.otherTotal ?? 0,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
public throughput = {
|
||||
|
||||
Reference in New Issue
Block a user