From e81d0386d68db9b006c9988f7ebb1eb85a6ec02e Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Mon, 23 Jun 2025 09:02:42 +0000 Subject: [PATCH] fix(metrics): fix metrics --- ts/proxies/smart-proxy/http-proxy-bridge.ts | 8 ++++++++ ts/proxies/smart-proxy/route-connection-handler.ts | 7 +------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/ts/proxies/smart-proxy/http-proxy-bridge.ts b/ts/proxies/smart-proxy/http-proxy-bridge.ts index b585d97..adbd89d 100644 --- a/ts/proxies/smart-proxy/http-proxy-bridge.ts +++ b/ts/proxies/smart-proxy/http-proxy-bridge.ts @@ -135,12 +135,20 @@ export class HttpProxyBridge { // Update stats if needed if (record) { record.bytesReceived += chunk.length; + // Also record in metrics collector for throughput tracking + if (this.smartProxy.metricsCollector) { + this.smartProxy.metricsCollector.recordBytes(record.id, chunk.length, 0); + } } }, onServerData: (chunk) => { // Update stats if needed if (record) { record.bytesSent += chunk.length; + // Also record in metrics collector for throughput tracking + if (this.smartProxy.metricsCollector) { + this.smartProxy.metricsCollector.recordBytes(record.id, 0, chunk.length); + } } }, onCleanup: (reason) => { diff --git a/ts/proxies/smart-proxy/route-connection-handler.ts b/ts/proxies/smart-proxy/route-connection-handler.ts index cf47865..5bb23d3 100644 --- a/ts/proxies/smart-proxy/route-connection-handler.ts +++ b/ts/proxies/smart-proxy/route-connection-handler.ts @@ -1114,14 +1114,9 @@ export class RouteConnectionHandler { // Store initial data if provided if (initialChunk) { - record.bytesReceived += initialChunk.length; + // Don't count bytes here - they will be counted when actually forwarded through bidirectional forwarding record.pendingData.push(Buffer.from(initialChunk)); record.pendingDataSize = initialChunk.length; - - // Record bytes for metrics - if (this.smartProxy.metricsCollector) { - this.smartProxy.metricsCollector.recordBytes(record.id, initialChunk.length, 0); - } } // Create the target socket with immediate error handling