collector/ethtool: skip full scan of NetClass directories

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 <will.jordan@gmail.com>
This commit is contained in:
Will Jordan 2025-02-07 12:39:33 -08:00
parent 5340ad60c0
commit ffd5a37cd9

View file

@ -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