fix(metrics): fix metrics
This commit is contained in:
@ -11,10 +11,11 @@
|
||||
- Hour 2: 2GB total / 60s = 34 MB/s ✗ (appears doubled!)
|
||||
- Hour 3: 3GB total / 60s = 50 MB/s ✗ (keeps rising!)
|
||||
|
||||
**Solution**: Implemented snapshot-based byte tracking that calculates actual bytes transferred within each time window:
|
||||
- Store periodic snapshots of byte counts with timestamps
|
||||
- Calculate delta between window start and end snapshots
|
||||
- Divide delta by window duration for accurate throughput
|
||||
**Solution**: Implemented dedicated ThroughputTracker instances for each route and IP address:
|
||||
- Each route and IP gets its own throughput tracker with per-second sampling
|
||||
- Samples are taken every second and stored in a circular buffer
|
||||
- Rate calculations use actual samples within the requested window
|
||||
- Default window is now 1 second for real-time accuracy
|
||||
|
||||
### What Gets Counted (Network Interface Throughput)
|
||||
|
||||
@ -53,15 +54,19 @@ The byte tracking is designed to match network interface throughput (what Unifi/
|
||||
|
||||
### Metrics Architecture
|
||||
|
||||
The metrics system has three layers:
|
||||
The metrics system has multiple layers:
|
||||
1. **Connection Records** (`record.bytesReceived/bytesSent`): Track total bytes per connection
|
||||
2. **ThroughputTracker**: Accumulates bytes between samples for global rate calculations (resets each second)
|
||||
3. **connectionByteTrackers**: Track bytes per connection with snapshots for accurate windowed per-route/IP metrics
|
||||
2. **Global ThroughputTracker**: Accumulates bytes between samples for overall rate calculations
|
||||
3. **Per-Route ThroughputTrackers**: Dedicated tracker for each route with per-second sampling
|
||||
4. **Per-IP ThroughputTrackers**: Dedicated tracker for each IP with per-second sampling
|
||||
5. **connectionByteTrackers**: Track cumulative bytes and metadata for active connections
|
||||
|
||||
Key features:
|
||||
- Global throughput uses sampling with accumulator reset (accurate)
|
||||
- Per-route/IP throughput uses snapshots to calculate window-specific deltas (accurate)
|
||||
- All throughput trackers sample every second (1Hz)
|
||||
- Each tracker maintains a circular buffer of samples (default: 1 hour retention)
|
||||
- Rate calculations are accurate for any requested window (default: 1 second)
|
||||
- All byte counting happens exactly once at the data flow point
|
||||
- Unused route/IP trackers are automatically cleaned up when connections close
|
||||
|
||||
### Understanding "High" Byte Counts
|
||||
|
||||
|
Reference in New Issue
Block a user