Skip to content

Commit 7f49a42

Browse files
committed
Add optional timestamp to metric output
Fixes #18
1 parent fdf2489 commit 7f49a42

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

cvmfs-client-prometheus.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
HTTP_HEADER='FALSE'
44
USE_NON_STANDARD_MOUNTPOINTS='FALSE'
5+
EPOCHTIME=''
56

67
TMPFILE=$(mktemp)
78

@@ -46,6 +47,7 @@ usage() {
4647
echo '' >&2
4748
echo ' --http: add the HTTP protocol header to the output' >&2
4849
echo ' --non-standard-mountpoints: use cvmfs_config status instead of findmnt to discover repositories' >&2
50+
echo ' --timestamp: add a timestamp to each metric' >&2
4951
echo '' >&2
5052
echo 'NOTE: The user running this script must have read access' >&2
5153
echo ' to the CVMFS cache files!' >&2
@@ -608,7 +610,7 @@ for cmd in attr bc cvmfs_config cvmfs_talk grep; do
608610
done
609611

610612
#############################################################
611-
args=$(getopt --options 'h' --longoptions 'help,http,non-standard-mountpoints' -- "$@")
613+
args=$(getopt --options 'h' --longoptions 'help,http,non-standard-mountpoints,timestamp' -- "$@")
612614
eval set -- "$args"
613615

614616
for arg in $@; do
@@ -628,6 +630,11 @@ for arg in $@; do
628630
USE_NON_STANDARD_MOUNTPOINTS='TRUE'
629631
shift
630632
;;
633+
--timestamp)
634+
# Add metric timestamp with a leading space to simplify adding
635+
EPOCHTIME=" $(date +%s)"
636+
shift
637+
;;
631638
-h | --help)
632639
# get help
633640
shift
@@ -665,6 +672,12 @@ if check_cvmfs_version_exact; then
665672
postprocess_metrics_for_2132
666673
fi
667674

675+
# Add timestamp to all metrics if requested
676+
if [[ -n "${EPOCHTIME}" ]]; then
677+
sed "/^#/! s/\$/${EPOCHTIME}/" "${TMPFILE}" > "${TMPFILE}.time"
678+
mv "${TMPFILE}.time" "${TMPFILE}"
679+
fi
680+
668681
if [[ "${HTTP_HEADER}" == 'TRUE' ]]; then
669682
content_length=$(stat --printf="%s" "${TMPFILE}")
670683
echo -ne "HTTP/1.1 200 OK\r\n"

0 commit comments

Comments
 (0)