From 27eeb4e56e41000e26d88a7991f63c4f13fe92e9 Mon Sep 17 00:00:00 2001 From: Thomas Lin Date: Tue, 31 Dec 2019 02:15:37 -0500 Subject: [PATCH] Fixed inaccurate 'node_network_speed_bytes' when speeds are low 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 --- CHANGELOG.md | 1 + collector/netclass_linux.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b65a3008ff..2f85f51263 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/collector/netclass_linux.go b/collector/netclass_linux.go index af4b48799b..8ec776bef5 100644 --- a/collector/netclass_linux.go +++ b/collector/netclass_linux.go @@ -141,7 +141,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) }