Skip to content

Commit

Permalink
Update error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mshahzeb committed Jul 11, 2024
1 parent aa95197 commit c27ccb5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
3 changes: 2 additions & 1 deletion blockdevice/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
37 changes: 20 additions & 17 deletions ext4/ext4.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package ext4

import (
"fmt"
"strings"
"path/filepath"

Expand All @@ -23,8 +24,8 @@ import (
)

const (
sysPath = "sys"
sysFSPath = "fs"
sysFSExt4Path = "ext4"
)

// Stats contains statistics for a single Btrfs filesystem.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c27ccb5

Please sign in to comment.