22
33HTTP_HEADER=' FALSE'
44USE_NON_STANDARD_MOUNTPOINTS=' FALSE'
5+ EPOCHTIME=' '
56
67TMPFILE=$( 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
608610done
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 ' -- " $@ " )
612614eval set -- " $args "
613615
614616for 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
666673fi
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+
668681if [[ " ${HTTP_HEADER} " == ' TRUE' ]]; then
669682 content_length=$( stat --printf=" %s" " ${TMPFILE} " )
670683 echo -ne " HTTP/1.1 200 OK\r\n"
0 commit comments