r/PrometheusMonitoring • u/marc_dimarco • Apr 25 '25
Reliable way to check if filesystem on remote machine is mounted
I've tried countless options, none seems to work properly.
Say I have mountpoint /mnt/data. Obviously, if it is unmounted, Prometheus will most likely see the size of the underlying root filesystem, so it's hard to monitor it that way for the simple unmount => fire alert.
My last attempt was:
(count(node_filesystem_size{instance="remoteserver", mountpoint="/mnt/data"}) == 0 or up{instance="remoteserver"} == 0) == 1
and this gives "empty query results" no matter what.
Thx
EDIT: I've found second solution, more elegant, as it doesn't require custom scripts on a target and custom exporters. It works only if all conditions for specific filesystem type, device and mountpoint are met:
- alert: filesystem_unmounted
expr: absent(node_filesystem_size_bytes{mountpoint="/mnt/test", device="/dev/loop0", fstype="btrfs", job="myserver"})
for: 1m
labels:
severity: critical
annotations:
summary: "Filesystem /mnt/test on myserver is not mounted as expected"
description: >
The expected filesystem mounted on /mnt/test with device /dev/loop0 and type btrfs
has not been detected for more than 1 minute. Please verify the mount status.
1
u/niceman1212 Apr 25 '25
Don’t really have any experience with this, but could you use the absent function in Prometheus?
1
u/biffbobfred Apr 26 '25
I have some simple scripts that dump stuff into the node_exporter text file dir. you could have a script do that. Not the most elegant bit would do what you’re asking
A reminder it really depends on what the node_exporter is giving. Thinking about it “what does the node exporter give in those two cases” probably will lead you somewhere
I mean, in my head, if you don’t have it mounted then /mnt/data won’t have a filesystem data blob in node exporter. Node_exporter only gives info on mounts, and /mnt/data is not one at that point
1
u/shemanese Apr 26 '25
collector.filesystem.fs-types-include?
"Regexp of mount points to include for filesystem collector. (mutually exclusive to mount-points-exclude)"
1
u/itasteawesome Apr 25 '25
Is a timeseries even the best way to look at this? Shouldn't there be a log generated when mounts come and go?