From 7188f54bbc2d071f570809630fc453bdfb3df6cb Mon Sep 17 00:00:00 2001 From: Sven Rebhan <36194019+srebhan@users.noreply.github.com> Date: Wed, 10 Apr 2024 11:14:11 -0400 Subject: [PATCH] chore(inputs.diskio): Add udev properties only if available (#15122) --- plugins/inputs/diskio/diskio_linux.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/plugins/inputs/diskio/diskio_linux.go b/plugins/inputs/diskio/diskio_linux.go index e541604d8..4af75f912 100644 --- a/plugins/inputs/diskio/diskio_linux.go +++ b/plugins/inputs/diskio/diskio_linux.go @@ -59,7 +59,7 @@ func (d *DiskIO) diskInfo(devName string) (map[string]string, error) { return nil, err } - // Read additional device properties + // Read additional (optional) device properties var sysBlockPath string if ok && len(ic.sysBlockPath) > 0 { // We can reuse the /sys block path from a "previous" entry. @@ -67,18 +67,16 @@ func (d *DiskIO) diskInfo(devName string) (map[string]string, error) { sysBlockPath = ic.sysBlockPath } else { sysBlockPath = "/sys/block/" + devName - if _, err := os.Stat(sysBlockPath); err != nil { - // Giving up, cannot retrieve additional info - return nil, err - } } + devInfo, err := readDevData(sysBlockPath) - if err != nil { + if err == nil { + for k, v := range devInfo { + info[k] = v + } + } else if !errors.Is(err, os.ErrNotExist) { return nil, err } - for k, v := range devInfo { - info[k] = v - } d.infoCache[devName] = diskInfoCache{ modifiedAt: stat.Mtim.Nano(),