From d514d67d7f7cd2f69551ad115ed11941a8f0a0f5 Mon Sep 17 00:00:00 2001 From: "W. Andrew Denton" Date: Wed, 20 Oct 2021 09:43:56 -0700 Subject: [PATCH] ethtool: convert updateSpeeds to a loop. Signed-off-by: W. Andrew Denton --- collector/ethtool_linux.go | 113 +++++++++++++------------------------ 1 file changed, 39 insertions(+), 74 deletions(-) diff --git a/collector/ethtool_linux.go b/collector/ethtool_linux.go index 0aa9239a..233cbd8f 100644 --- a/collector/ethtool_linux.go +++ b/collector/ethtool_linux.go @@ -38,12 +38,6 @@ import ( "gopkg.in/alecthomas/kingpin.v2" ) -const ( - // These are in _bytes_ to match bytes-per-second speeds from netclass. - Mbps = 1000000.0 / 8.0 - Gbps = 1000.0 * Mbps -) - var ( ethtoolDeviceInclude = kingpin.Flag("collector.ethtool.device-include", "Regexp of ethtool devices to include (mutually exclusive to device-exclude).").String() ethtoolDeviceExclude = kingpin.Flag("collector.ethtool.device-exclude", "Regexp of ethtool devices to exclude (mutually exclusive to device-include).").String() @@ -268,75 +262,46 @@ func (c *ethtoolCollector) updatePortInfo(ch chan<- prometheus.Metric, device st // https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/ethtool.h func (c *ethtoolCollector) updateSpeeds(ch chan<- prometheus.Metric, prefix string, device string, linkModes uint32) { linkMode := fmt.Sprintf("%s_speed", prefix) + const ( + full = "full" + half = "half" + // This is in _bytes_ to match bytes-per-second speeds from netclass. + Mbps = 1000000.0 / 8.0 + ) - if linkModes&(1<