Skip to content

Commit

Permalink
Use /proc/mounts instead of statfs(2) for ro state (prometheus#1002)
Browse files Browse the repository at this point in the history
While the statfs(2) approach is reliable for normally mounted filesystems, the
flags returned can be inconsistent when filesystem has been remounted read-only
after encountering an error. The returned flags do accurately represent the
internal state of the filesystem, but they do not reflect whether the VFS layer
will accept writes. Instead, it makes sense to parse the current VFS mount
state from the options field in /proc/mounts since it takes precedence.

Signed-off-by: Brandon Gilmore <bgilmore@valvesoftware.com>
  • Loading branch information
bgilmore authored and oblitorum committed Apr 9, 2024
1 parent 8b8a62c commit 99b2f64
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion collector/filesystem_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type filesystemCollector struct {
}

type filesystemLabels struct {
device, mountPoint, fsType string
device, mountPoint, fsType, options string
}

type filesystemStats struct {
Expand Down
8 changes: 6 additions & 2 deletions collector/filesystem_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,11 @@ func (c *filesystemCollector) GetStats() ([]filesystemStats, error) {
}

var ro float64
if (buf.Flags & readOnly) != 0 {
ro = 1
for _, option := range strings.Split(labels.options, ",") {
if option == "ro" {
ro = 1
break
}
}

stats = append(stats, filesystemStats{
Expand Down Expand Up @@ -150,6 +153,7 @@ func mountPointDetails() ([]filesystemLabels, error) {
device: parts[0],
mountPoint: parts[1],
fsType: parts[2],
options: parts[3],
})
}
return filesystems, scanner.Err()
Expand Down

0 comments on commit 99b2f64

Please sign in to comment.