diff --git a/collector/diskstats_linux.go b/collector/diskstats_linux.go index 134c19e299..af50de0fc0 100644 --- a/collector/diskstats_linux.go +++ b/collector/diskstats_linux.go @@ -260,7 +260,7 @@ func NewDiskstatsCollector(logger *slog.Logger) (Collector, error) { } // Only enable getting device properties from udev if the directory is readable. - if stat, err := os.Stat(*udevDataPath); err != nil || !stat.IsDir() { + if stat, err := os.Stat(udevDataFilePath("")); err != nil || !stat.IsDir() { logger.Error("Failed to open directory, disabling udev device properties", "path", *udevDataPath) } else { collector.getUdevDeviceProperties = getUdevDeviceProperties diff --git a/collector/paths.go b/collector/paths.go index 82c941876d..20d64a588d 100644 --- a/collector/paths.go +++ b/collector/paths.go @@ -42,6 +42,10 @@ func rootfsFilePath(name string) string { } func udevDataFilePath(name string) string { + // If rootfsPath flag is set, prepend to the udev data path + if *rootfsPath != "/" { + return filepath.Join(*rootfsPath, *udevDataPath, name) + } return filepath.Join(*udevDataPath, name) }