Skip to content

Commit 3ddc82c

Browse files
t-linSuperQ
authored andcommitted
Fixed inaccurate 'node_network_speed_bytes' when speeds are low (#1580)
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 <[email protected]>
1 parent f316099 commit 3ddc82c

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
* [BUGFIX] Strip path.rootfs from mountpoint labels #1421
3535
* [BUGFIX] Fix empty string in path.rootfs #1464
3636
* [BUGFIX] Fix typo in cpufreq metric names #1510
37+
* [BUGFIX] Fix network speed math #1580
3738

3839
## 0.18.1 / 2019-06-04
3940

collector/netclass_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (c *netClassCollector) Update(ch chan<- prometheus.Metric) error {
144144
}
145145

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

0 commit comments

Comments
 (0)