Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading