Report network throughput in bits, which is what everything downstream says
/proc/net/dev counts octets; the field is named rx_bps, vvFmtBps renders Kb/s and Mb/s, and the Monitor card prints it directly under the NIC link speed from /sys/class/net/*/speed, which genuinely is megabits. So the one figure you would read against the link understated traffic eightfold — 811 KB/s shown as "0.8 Mb/s" beside a 10 Gb/s link when it was 6.5. Converted at the source so the field name stops lying; both consumers are bit-labelled or relative.
This commit is contained in:
@@ -394,10 +394,21 @@ function vv_network_stats(): array {
|
||||
file_put_contents($tmp, json_encode($now));
|
||||
rename($tmp, $stateFile);
|
||||
|
||||
// ×8, because /proc/net/dev counts octets and everything downstream of here says bits.
|
||||
//
|
||||
// The field is named rx_bps, vvFmtBps() renders it as Kb/s, Mb/s and Gb/s, and the Monitor
|
||||
// card prints it directly beneath the NIC's link speed — which comes from
|
||||
// /sys/class/net/*/speed and genuinely is megabits. So the one number on that card you would
|
||||
// read against the link was understating traffic by a factor of eight: 811 KB/s of real
|
||||
// traffic displayed as "0.8 Mb/s" next to a 10 Gb/s link, when it was 6.5 Mb/s.
|
||||
//
|
||||
// Converted at the source rather than in the formatter so the field name stops lying. Both
|
||||
// consumers are the Monitor card's rate readout and its history graph, and both are relative
|
||||
// or bit-labelled, so neither changes meaning — only magnitude, to the correct one.
|
||||
$rxRate = $txRate = 0;
|
||||
if (!empty($prev['ts']) && ($dt = $now['ts'] - $prev['ts']) > 0.1) {
|
||||
$rxRate = max(0, (int)(($rxBytes - ($prev['rx'] ?? $rxBytes)) / $dt));
|
||||
$txRate = max(0, (int)(($txBytes - ($prev['tx'] ?? $txBytes)) / $dt));
|
||||
$rxRate = max(0, (int)(($rxBytes - ($prev['rx'] ?? $rxBytes)) * 8 / $dt));
|
||||
$txRate = max(0, (int)(($txBytes - ($prev['tx'] ?? $txBytes)) * 8 / $dt));
|
||||
}
|
||||
|
||||
$speedMbps = (int)@file_get_contents("/sys/class/net/$iface/speed");
|
||||
|
||||
Reference in New Issue
Block a user