feat(metrics): add per-IP and HTTP-request metrics, propagate source IP through proxy paths, and expose new metrics to the TS adapter

This commit is contained in:
2026-02-14 11:15:17 +00:00
parent 6c84aedee1
commit f80cdcf41c
9 changed files with 504 additions and 102 deletions

View File

@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartproxy',
version: '25.1.0',
version: '25.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.'
}

View File

@@ -72,12 +72,23 @@ export class RustMetricsAdapter implements IMetrics {
return result;
},
byIP: (): Map<string, number> => {
// Per-IP tracking not yet available from Rust
return new Map();
const result = new Map<string, number>();
if (this.cache?.ips) {
for (const [ip, im] of Object.entries(this.cache.ips)) {
result.set(ip, (im as any).activeConnections ?? 0);
}
}
return result;
},
topIPs: (_limit?: number): Array<{ ip: string; count: number }> => {
// Per-IP tracking not yet available from Rust
return [];
topIPs: (limit: number = 10): Array<{ ip: string; count: number }> => {
const result: Array<{ ip: string; count: number }> = [];
if (this.cache?.ips) {
for (const [ip, im] of Object.entries(this.cache.ips)) {
result.push({ ip, count: (im as any).activeConnections ?? 0 });
}
}
result.sort((a, b) => b.count - a.count);
return result.slice(0, limit);
},
};
@@ -100,9 +111,13 @@ export class RustMetricsAdapter implements IMetrics {
custom: (_seconds: number): IThroughputData => {
return this.throughput.instant();
},
history: (_seconds: number): Array<IThroughputHistoryPoint> => {
// Throughput history not yet available from Rust
return [];
history: (seconds: number): Array<IThroughputHistoryPoint> => {
if (!this.cache?.throughputHistory) return [];
return this.cache.throughputHistory.slice(-seconds).map((p: any) => ({
timestamp: p.timestampMs,
in: p.bytesIn,
out: p.bytesOut,
}));
},
byRoute: (_windowSeconds?: number): Map<string, IThroughputData> => {
const result = new Map<string, IThroughputData>();
@@ -117,21 +132,28 @@ export class RustMetricsAdapter implements IMetrics {
return result;
},
byIP: (_windowSeconds?: number): Map<string, IThroughputData> => {
return new Map();
const result = new Map<string, IThroughputData>();
if (this.cache?.ips) {
for (const [ip, im] of Object.entries(this.cache.ips)) {
result.set(ip, {
in: (im as any).throughputInBytesPerSec ?? 0,
out: (im as any).throughputOutBytesPerSec ?? 0,
});
}
}
return result;
},
};
public requests = {
perSecond: (): number => {
// Rust tracks connections, not HTTP requests (TCP-level proxy)
return 0;
return this.cache?.httpRequestsPerSec ?? 0;
},
perMinute: (): number => {
return 0;
return (this.cache?.httpRequestsPerSecRecent ?? 0) * 60;
},
total: (): number => {
// Use total connections as a proxy for total requests
return this.cache?.totalConnections ?? 0;
return this.cache?.totalHttpRequests ?? this.cache?.totalConnections ?? 0;
},
};