prometheus / node_exporter

Exporter for machine metrics
https://prometheus.io/
Apache License 2.0
11.1k stars 2.35k forks source link

Metric "node_filesystem_readonly" does not include super options when calculating #3157

Open duanchao2035 opened 2 days ago

duanchao2035 commented 2 days ago

Question description

Hello, I would like to ask a question. When using node-exporter for metric collection, I have noticed an inconsistency in the behavior of the metric "node_filesystem_readonly" across different versions. In version 1.6.1, the value is obtained through /proc/1/mounts' options, while in the latest version, it is obtained through /proc/1/mountinfo. When I execute the following commands on the host with a read-only root partition:

cat /proc/1/mountinfo | grep /dev/md127
44 0 9:127 / / rw,relatime shared:1 - ext4 /dev/md127 ro
cat /proc/1/mounts | grep md127
/dev/md127 / ext4 ro,relatime 0 0

As per the code logic, in version 1.6.1, the "ro" value is 1, whereas in the latest version, it is 0 (the options value in the new version's file does not include "ro", but the super options include it). I would like to confirm whether this metric's meaning does not include cases where super options are set to "ro".

The PR that caused this question: https://github.com/prometheus/node_exporter/commit/b9d0932179a0c5b3a8863f3d6cdafe8584cedc8e

Host operating system: output of uname -a

Linux host 4.19.90-2307.3.0.el7.v60.x86_64 #1 SMP Mon Aug 26 14:27:04 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

node_exporter version: output of node_exporter --version

node_exporter, version 1.6.1 (branch: HEAD, revision: 4a1b77600c1873a8233f3ffb55afcedbb63b8d84) build user: root@586879db11e5 build date: 20230717-12:10:52 go version: go1.20.6 platform: linux/amd64 tags: netgo osusergo static_build

node_exporter command line flags

node_exporter log output

Are you running node_exporter in Docker?

no

What did you do that produced an error?

Make the root partition read-only

What did you expect to see?

The node_filesystem_readonly{mountpoint="/"} is set to 1 when the root partition is read-only.

What did you see instead?

The node_filesystem_readonly{mountpoint="/"} is set to 0 when the root partition is read-only.

dswarbrick commented 1 day ago

In filesystem_linux.go, you can see that it parses the mount options from the sixth field group, i.e. rw,relatime in your case. It ignores the super-options completely.

Excerpt from mount(2) manpage:

       Since Linux 2.6.16, MS_RDONLY can be set or cleared on a per-
       mount-point basis as well as on the underlying filesystem
       superblock.  The mounted filesystem will be writable only if
       neither the filesystem nor the mountpoint are flagged as read-
       only.

So for the node_filesystem_readonly metric to have any real meaning, it would need to take both the per-mount options and per-superblock options into account.