Skip to content

Commit

Permalink
Fixed inaccurate 'node_network_speed_bytes' when speeds are low (#1580)
Browse files Browse the repository at this point in the history
Integer division and the order of operations when converting Mbps to Bps
results in a loss of accuracy if the interface speeds are set low.
e.g. 100 Mbps is reported as 12000000 Bps, should be 12500000
     10 Mbps is reported as 1000000 Bps, should be 1250000

Signed-off-by: Thomas Lin <t.lin@mail.utoronto.ca>
  • Loading branch information
t-lin authored and SuperQ committed Jan 1, 2020
1 parent f316099 commit 3ddc82c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* [BUGFIX] Strip path.rootfs from mountpoint labels #1421
* [BUGFIX] Fix empty string in path.rootfs #1464
* [BUGFIX] Fix typo in cpufreq metric names #1510
* [BUGFIX] Fix network speed math #1580

## 0.18.1 / 2019-06-04

Expand Down
2 changes: 1 addition & 1 deletion collector/netclass_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (c *netClassCollector) Update(ch chan<- prometheus.Metric) error {
}

if ifaceInfo.Speed != nil {
speedBytes := int64(*ifaceInfo.Speed / 8 * 1000 * 1000)
speedBytes := int64(*ifaceInfo.Speed * 1000 * 1000 / 8)
pushMetric(ch, c.subsystem, "speed_bytes", speedBytes, ifaceInfo.Name, prometheus.GaugeValue)
}

Expand Down

0 comments on commit 3ddc82c

Please sign in to comment.