diff --git a/app/Services/WgTraffic.php b/app/Services/WgTraffic.php index ce3f6d1..08c9892 100644 --- a/app/Services/WgTraffic.php +++ b/app/Services/WgTraffic.php @@ -42,7 +42,7 @@ class WgTraffic $idx = (int) floor(($t - $from) / $width); if ($idx >= 0 && $idx < $buckets) { $down[$idx] += $dRx; - $up[$idx] += (int) $r->tx; + $up[$idx] += $dTx; } } $prev[$pk] = ['rx' => (int) $r->rx, 'tx' => (int) $r->tx]; diff --git a/tests/Feature/WgTrafficTest.php b/tests/Feature/WgTrafficTest.php index 983f221..8ce4465 100644 --- a/tests/Feature/WgTrafficTest.php +++ b/tests/Feature/WgTrafficTest.php @@ -37,8 +37,10 @@ class WgTrafficTest extends TestCase $this->sample('B', 50, 5, 600); $s = app(WgTraffic::class)->series(3600, 6); + // Both directions are THROUGHPUT (sum of positive per-peer deltas), not raw counters: + // down = A(100+200)+B(50) = 350 ; up = A(10+20)+B(5) = 35. $this->assertSame(350, $s['total_down']); - $this->assertSame(45, $s['total_up']); + $this->assertSame(35, $s['total_up']); $this->assertGreaterThan(0, $s['peak_down']); }