1515package ext4
1616
1717import (
18+ "fmt"
1819 "strings"
1920 "path/filepath"
2021
@@ -23,8 +24,8 @@ import (
2324)
2425
2526const (
26- sysPath = "sys"
2727 sysFSPath = "fs"
28+ sysFSExt4Path = "ext4"
2829)
2930
3031// Stats contains statistics for a single Btrfs filesystem.
@@ -79,24 +80,26 @@ func (fs FS) ProcStat() ([]*Stats, error) {
7980
8081 stats := make ([]* Stats , 0 , len (matches ))
8182 for _ , m := range matches {
82- s := & Stats {}
83- for file , p := range map [string ]* uint64 {
84- "errors_count" : & s .Errors ,
85- "warning_count" : & s .Warnings ,
86- "msg_count" : & s .Messages ,
87- } {
88- var val uint64
89- val , err = util .ReadUintFromFile (fs .sys .Path (m , file ))
90- if err != nil {
91- return nil , err
92- }
83+ s := & Stats {}
84+
85+ // "*" used in glob above indicates the name of the filesystem.
86+ name := filepath .Base (m )
87+ s .Name = name
88+ for file , p := range map [string ]* uint64 {
89+ "errors_count" : & s .Errors ,
90+ "warning_count" : & s .Warnings ,
91+ "msg_count" : & s .Messages ,
92+ } {
93+ var val uint64
94+ val , err = util .ReadUintFromFile (fs .sys .Path (sysFSPath , sysFSExt4Path , name , file ))
95+ if err != nil {
96+ fmt .Errorf ("failed to read ext4 stats from %s: %w" , file , err )
97+ } else {
9398 * p = val
94- }
99+ }
100+ }
95101
96- // "*" used in glob above indicates the name of the filesystem.
97- name := filepath .Base (filepath .Dir (filepath .Dir (m )))
98- s .Name = name
99- stats = append (stats , s )
102+ stats = append (stats , s )
100103 }
101104
102105 return stats , nil
0 commit comments