chore(inputs.diskio): Add udev properties only if available (#15122)
This commit is contained in:
parent
5e1a3cc8ca
commit
7188f54bbc
|
|
@ -59,7 +59,7 @@ func (d *DiskIO) diskInfo(devName string) (map[string]string, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read additional device properties
|
// Read additional (optional) device properties
|
||||||
var sysBlockPath string
|
var sysBlockPath string
|
||||||
if ok && len(ic.sysBlockPath) > 0 {
|
if ok && len(ic.sysBlockPath) > 0 {
|
||||||
// We can reuse the /sys block path from a "previous" entry.
|
// 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
|
sysBlockPath = ic.sysBlockPath
|
||||||
} else {
|
} else {
|
||||||
sysBlockPath = "/sys/block/" + devName
|
sysBlockPath = "/sys/block/" + devName
|
||||||
if _, err := os.Stat(sysBlockPath); err != nil {
|
|
||||||
// Giving up, cannot retrieve additional info
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
devInfo, err := readDevData(sysBlockPath)
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
for k, v := range devInfo {
|
|
||||||
info[k] = v
|
|
||||||
}
|
|
||||||
|
|
||||||
d.infoCache[devName] = diskInfoCache{
|
d.infoCache[devName] = diskInfoCache{
|
||||||
modifiedAt: stat.Mtim.Nano(),
|
modifiedAt: stat.Mtim.Nano(),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue