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.
  • Loading branch information
anarcat committed Jan 9, 2025
1 parent a2b43e1 commit 9a81b73
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions path-timestamp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

# Expose timestamp of given path
#
# 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"
done

0 comments on commit 9a81b73

Please sign in to comment.