Skip to content

add helper script to extract timestamps from files #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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