diff --git a/path-timestamp.sh b/path-timestamp.sh new file mode 100644 index 0000000..b16caea --- /dev/null +++ b/path-timestamp.sh @@ -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é + +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