chore(inputs.diskio): Add udev properties only if available (#15122)

This commit is contained in:
Sven Rebhan 2024-04-10 11:14:11 -04:00 committed by GitHub
parent 5e1a3cc8ca
commit 7188f54bbc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 9 deletions

View File

@ -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(),