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 <will.jordan@gmail.com>
superq/systemd_shutdown
Will Jordan 2025-02-15 00:32:59 -08:00 committed by GitHub
parent 2f2113376f
commit edc40d1e0b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 2 deletions

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