From e22301c0dd1779dbee2e70c33982354a427e348e Mon Sep 17 00:00:00 2001 From: czephyr Date: Mon, 23 Dec 2024 22:42:17 +0100 Subject: [PATCH] path.udev.data handling rootfs --- collector/diskstats_linux.go | 2 +- collector/paths.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) 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) }