fix(metrics): fix metrics

This commit is contained in:
Juergen Kunz
2025-06-23 09:02:42 +00:00
parent fc210eca8b
commit e81d0386d6
2 changed files with 9 additions and 6 deletions

View File

@ -135,12 +135,20 @@ export class HttpProxyBridge {
// Update stats if needed // Update stats if needed
if (record) { if (record) {
record.bytesReceived += chunk.length; 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) => { onServerData: (chunk) => {
// Update stats if needed // Update stats if needed
if (record) { if (record) {
record.bytesSent += chunk.length; 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) => { onCleanup: (reason) => {

View File

@ -1114,14 +1114,9 @@ export class RouteConnectionHandler {
// Store initial data if provided // Store initial data if provided
if (initialChunk) { 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.pendingData.push(Buffer.from(initialChunk));
record.pendingDataSize = initialChunk.length; 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 // Create the target socket with immediate error handling