Skip to content

Commit

Permalink
lustre2: don't fail plugin if can't read brw_stats
Browse files Browse the repository at this point in the history
Before this commit, the plugin entirely fails when run as anyone other
than root, because brw_stats files are symlinks to /sys/kernel/debug/.

Which was causing errors like this:
```
2024-03-22T02:40:40Z E! [inputs.lustre2] Error in plugin: failed to read file /proc/fs/lustre/osd-ldiskfs/MGS/brw_stats: open /proc/fs/lustre/osd-ldiskfs/MGS/brw_stats: permission denied
```

After this change, the plugin continues to run and gather whatever
metrics it can, even if brw_stats files are unreadable.
  • Loading branch information
lukeyeager committed Mar 22, 2024
1 parent 2dde6a0 commit bed31ce
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions plugins/inputs/lustre2/lustre2.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ type tags struct {
// Lustre proc files can change between versions, so we want to future-proof
// by letting people choose what to look at.
type Lustre2 struct {
OstProcfiles []string `toml:"ost_procfiles"`
MdsProcfiles []string `toml:"mds_procfiles"`
OstProcfiles []string `toml:"ost_procfiles"`
MdsProcfiles []string `toml:"mds_procfiles"`
Log telegraf.Logger `toml:"-"`

// used by the testsuite to generate mock sysfs and procfs files
rootdir string
Expand Down Expand Up @@ -525,7 +526,12 @@ func (l *Lustre2) getLustreProcBrwStats(fileglob string, wantedFields []*mapping

wholeFile, err := os.ReadFile(file)
if err != nil {
return fmt.Errorf("failed to read file %s: %w", file, err)
if strings.Contains(err.Error(), "permission denied") {
l.Log.Debugf("failed to read file %s: %w", file, err)
continue
} else {
return fmt.Errorf("failed to read file %s: %w", file, err)
}
}
lines := strings.Split(string(wholeFile), "\n")

Expand Down

0 comments on commit bed31ce

Please sign in to comment.