diff --git a/CHANGELOG.md b/CHANGELOG.md index 724f387e..e54dd425 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Changes * [BUGFIX] +* [BUGFIX] Add fallback for missing /proc/1/mounts #1172 * [CHANGE] Add TCPSynRetrans to netstat default filter #1143 * [ENHANCEMENT] Add Infiniband counters #1120 * [FEATURE] Add a flag to disable exporter metrics #1148 diff --git a/collector/filesystem_linux.go b/collector/filesystem_linux.go index e7a692ec..673078bb 100644 --- a/collector/filesystem_linux.go +++ b/collector/filesystem_linux.go @@ -135,6 +135,11 @@ func stuckMountWatcher(mountPoint string, success chan struct{}) { func mountPointDetails() ([]filesystemLabels, error) { file, err := os.Open(procFilePath("1/mounts")) + if os.IsNotExist(err) { + // Fallback to `/proc/mounts` if `/proc/1/mounts` is missing due hidepid. + log.Debugf("Got %q reading root mounts, falling back to system mounts", err) + file, err = os.Open(procFilePath("mounts")) + } if err != nil { return nil, err } diff --git a/collector/filesystem_linux_test.go b/collector/filesystem_linux_test.go index 17c2d165..ebc6659c 100644 --- a/collector/filesystem_linux_test.go +++ b/collector/filesystem_linux_test.go @@ -91,3 +91,24 @@ func TestMountPointDetails(t *testing.T) { } } } + +func TestMountsFallback(t *testing.T) { + if _, err := kingpin.CommandLine.Parse([]string{"--path.procfs", "./fixtures_hidepid/proc"}); err != nil { + t.Fatal(err) + } + + expected := map[string]string{ + "/": "", + } + + filesystems, err := mountPointDetails() + if err != nil { + t.Log(err) + } + + for _, fs := range filesystems { + if _, ok := expected[fs.mountPoint]; !ok { + t.Errorf("Got unexpected %s", fs.mountPoint) + } + } +} diff --git a/collector/fixtures_hidepid/proc/mounts b/collector/fixtures_hidepid/proc/mounts new file mode 100644 index 00000000..fb6a9635 --- /dev/null +++ b/collector/fixtures_hidepid/proc/mounts @@ -0,0 +1 @@ +rootfs / rootfs rw 0 0