diff options
author | Brandon Gilmore <brandon@nullroute.com> | 2018-07-16 06:56:27 -0700 |
---|---|---|
committer | Ben Kochie <superq@gmail.com> | 2018-07-16 15:56:27 +0200 |
commit | 76bbd8dd1865b63e52fd19322e84a1bb4ea97b29 (patch) | |
tree | 63efa0aedf42b1a8cf471a32dfbb78631f01ad44 /collector/filesystem_linux.go | |
parent | c4102f117584f92e18e9612d9a9eecd0815e89bd (diff) | |
download | prometheus_node_collector-76bbd8dd1865b63e52fd19322e84a1bb4ea97b29.tar.bz2 prometheus_node_collector-76bbd8dd1865b63e52fd19322e84a1bb4ea97b29.tar.xz prometheus_node_collector-76bbd8dd1865b63e52fd19322e84a1bb4ea97b29.zip |
Use /proc/mounts instead of statfs(2) for ro state (#1002)
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>
Diffstat (limited to 'collector/filesystem_linux.go')
-rw-r--r-- | collector/filesystem_linux.go | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/collector/filesystem_linux.go b/collector/filesystem_linux.go index 78e0aea..eedce00 100644 --- a/collector/filesystem_linux.go +++ b/collector/filesystem_linux.go | |||
@@ -91,8 +91,11 @@ func (c *filesystemCollector) GetStats() ([]filesystemStats, error) { | |||
91 | } | 91 | } |
92 | 92 | ||
93 | var ro float64 | 93 | var ro float64 |
94 | if (buf.Flags & readOnly) != 0 { | 94 | for _, option := range strings.Split(labels.options, ",") { |
95 | ro = 1 | 95 | if option == "ro" { |
96 | ro = 1 | ||
97 | break | ||
98 | } | ||
96 | } | 99 | } |
97 | 100 | ||
98 | stats = append(stats, filesystemStats{ | 101 | stats = append(stats, filesystemStats{ |
@@ -150,6 +153,7 @@ func mountPointDetails() ([]filesystemLabels, error) { | |||
150 | device: parts[0], | 153 | device: parts[0], |
151 | mountPoint: parts[1], | 154 | mountPoint: parts[1], |
152 | fsType: parts[2], | 155 | fsType: parts[2], |
156 | options: parts[3], | ||
153 | }) | 157 | }) |
154 | } | 158 | } |
155 | return filesystems, scanner.Err() | 159 | return filesystems, scanner.Err() |