diff --git a/blockdevice/stats.go b/blockdevice/stats.go index 72871c79..5a9836d0 100644 --- a/blockdevice/stats.go +++ b/blockdevice/stats.go @@ -497,8 +497,9 @@ func (fs FS) SysBlockDeviceIOStat(device string) (IODeviceStats, error) { val, err = util.ReadHexFromFile(fs.sys.Path(sysBlockPath, device, sysDevicePath, file)) if err != nil { return IODeviceStats{}, err + } else { + *p = val } - *p = val } return ioDeviceStats, nil } \ No newline at end of file diff --git a/ext4/ext4.go b/ext4/ext4.go index 3bb579c3..441368fc 100644 --- a/ext4/ext4.go +++ b/ext4/ext4.go @@ -15,6 +15,7 @@ package ext4 import ( + "fmt" "strings" "path/filepath" @@ -23,8 +24,8 @@ import ( ) const ( - sysPath = "sys" sysFSPath = "fs" + sysFSExt4Path = "ext4" ) // Stats contains statistics for a single Btrfs filesystem. @@ -79,24 +80,26 @@ func (fs FS) ProcStat() ([]*Stats, error) { stats := make([]*Stats, 0, len(matches)) for _, m := range matches { - s := &Stats{} - for file, p := range map[string]*uint64{ - "errors_count": &s.Errors, - "warning_count": &s.Warnings, - "msg_count": &s.Messages, - } { - var val uint64 - val, err = util.ReadUintFromFile(fs.sys.Path(m, file)) - if err != nil { - return nil, err - } + s := &Stats{} + + // "*" used in glob above indicates the name of the filesystem. + name := filepath.Base(m) + s.Name = name + for file, p := range map[string]*uint64{ + "errors_count": &s.Errors, + "warning_count": &s.Warnings, + "msg_count": &s.Messages, + } { + var val uint64 + val, err = util.ReadUintFromFile(fs.sys.Path(sysFSPath, sysFSExt4Path, name, file)) + if err != nil { + fmt.Errorf("failed to read ext4 stats from %s: %w", file, err) + } else { *p = val - } + } + } - // "*" used in glob above indicates the name of the filesystem. - name := filepath.Base(filepath.Dir(filepath.Dir(m))) - s.Name = name - stats = append(stats, s) + stats = append(stats, s) } return stats, nil