Skip to content

Commit

Permalink
add helper script to extract timestamps from files
Browse files Browse the repository at this point in the history
This is a pretty simple tool, but we've found this useful to check
some diagnostics. We've also found alternatives like:

https://github.com/Puppet-Finland/prometheus-file-age-metrics/blob/main/create-file-age-metrics.sh

... which gives you a metric like "out of date files", which didn't
like, because the threshold lives in the script instead of the
alerting layer (which we prefer).

The closest thing to this is the filestat exporter:

https://github.com/michael-doubez/filestat_exporter

... which provides way more metrics and seems overengineered for our
purpose.

Signed-off-by: Antoine Beaupré <[email protected]>
  • Loading branch information
anarcat committed Jan 10, 2025
1 parent a2b43e1 commit a0920cd
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions path-timestamp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh

# Expose timestamp of given path
#
# This will provide the last modification timestamp (technically,
# stat(1)'s %Y parameter), which is a number of seconds since the
# epoch, once per provided path. It will claim the timestamp is zero
# if stat(1) fails to extract the timestamp for any reason.
#
# Usage: add this to crontab:
#
# */5 * * * * prometheus path-timestamp.sh /var/lib/prometheus | sponge /var/lib/node_exporter/path-timestamp.prom
#
# Author: Antoine Beaupré <[email protected]>

echo "# HELP node_path_modification_timestamp_seconds Last change timestamp"
echo "# TYPE node_path_modification_timestamp_seconds gauge"
for path in "$@"; do
printf 'node_path_modification_timestamp_seconds{path="%s"} ' "$path"
stat -c %Y "$path" 2>/dev/null || echo 0
done

0 comments on commit a0920cd

Please sign in to comment.