From edc40d1e0b67e0c349c1648857199c8e4b5e99ac Mon Sep 17 00:00:00 2001 From: Will Jordan Date: Sat, 15 Feb 2025 00:32:59 -0800 Subject: [PATCH] collector/ethtool: skip full scan of NetClass directories (#3239) ethtool only uses the device names from `NetClassDevices()`, not the whole NetClass data from `NetClass()`. Improves ethtool collector performance on systems with lots of excluded devices. Signed-off-by: Will Jordan --- collector/ethtool_linux.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/collector/ethtool_linux.go b/collector/ethtool_linux.go index da6be30b..78f7afe2 100644 --- a/collector/ethtool_linux.go +++ b/collector/ethtool_linux.go @@ -372,7 +372,7 @@ func (c *ethtoolCollector) updateSpeeds(ch chan<- prometheus.Metric, prefix stri } func (c *ethtoolCollector) Update(ch chan<- prometheus.Metric) error { - netClass, err := c.fs.NetClass() + netClass, err := c.fs.NetClassDevices() if err != nil { if errors.Is(err, os.ErrNotExist) || errors.Is(err, os.ErrPermission) { c.logger.Debug("Could not read netclass file", "err", err) @@ -385,7 +385,7 @@ func (c *ethtoolCollector) Update(ch chan<- prometheus.Metric) error { return fmt.Errorf("no network devices found") } - for device := range netClass { + for _, device := range netClass { var stats map[string]uint64 var err error