Skip to content

Commit

Permalink
collector/diskstats: Ignore udev when directory unreadable
Browse files Browse the repository at this point in the history
Log a single error message when the udev data directory (`/run/udev/data` by
default) is unreadable, and then don't try to get device properties out of it.

Also lower the log level from error to debug when we can't parse the udev files
properly, since these messages would be sent every time the node exporter gets
scraped.

Signed-off-by: Benoît Knecht <bknecht@protonmail.ch>
  • Loading branch information
BenoitKnecht committed Jul 5, 2022
1 parent 76273ea commit e6e1b4d
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions collector/diskstats_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,15 @@ func (d *typedFactorDesc) mustNewConstMetric(value float64, labels ...string) pr
}

type diskstatsCollector struct {
deviceFilter deviceFilter
fs blockdevice.FS
infoDesc typedFactorDesc
descs []typedFactorDesc
filesystemInfoDesc typedFactorDesc
deviceMapperInfoDesc typedFactorDesc
ataDescs map[string]typedFactorDesc
logger log.Logger
deviceFilter deviceFilter
fs blockdevice.FS
infoDesc typedFactorDesc
descs []typedFactorDesc
filesystemInfoDesc typedFactorDesc
deviceMapperInfoDesc typedFactorDesc
ataDescs map[string]typedFactorDesc
logger log.Logger
getUdevDeviceProperties func(uint32, uint32) (udevInfo, error)
}

func init() {
Expand All @@ -105,7 +106,7 @@ func NewDiskstatsCollector(logger log.Logger) (Collector, error) {
return nil, fmt.Errorf("failed to parse device filter flags: %w", err)
}

return &diskstatsCollector{
collector := diskstatsCollector{
deviceFilter: deviceFilter,
fs: fs,
infoDesc: typedFactorDesc{
Expand Down Expand Up @@ -256,7 +257,16 @@ func NewDiskstatsCollector(logger log.Logger) (Collector, error) {
},
},
logger: logger,
}, nil
}

// Only enable getting device properties from udev if the directory is readable.
if stat, err := os.Stat(*udevDataPath); err != nil || !stat.IsDir() {
level.Error(logger).Log("msg", "Failed to open directory, disabling udev device properties", "path", *udevDataPath)
} else {
collector.getUdevDeviceProperties = getUdevDeviceProperties
}

return &collector, nil
}

func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error {
Expand All @@ -273,7 +283,7 @@ func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error {

info, err := getUdevDeviceProperties(stats.MajorNumber, stats.MinorNumber)
if err != nil {
level.Error(c.logger).Log("msg", "Failed to parse udev info", "err", err)
level.Debug(c.logger).Log("msg", "Failed to parse udev info", "err", err)
}

ch <- c.infoDesc.mustNewConstMetric(1.0, dev,
Expand Down

0 comments on commit e6e1b4d

Please sign in to comment.