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
15 changes: 14 additions & 1 deletion cvmfs-client-prometheus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

HTTP_HEADER='FALSE'
USE_NON_STANDARD_MOUNTPOINTS='FALSE'
EPOCHTIME=''

TMPFILE=$(mktemp)

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

#############################################################
args=$(getopt --options 'h' --longoptions 'help,http,non-standard-mountpoints' -- "$@")
args=$(getopt --options 'h' --longoptions 'help,http,non-standard-mountpoints,timestamp' -- "$@")
eval set -- "$args"

for arg in $@; do
Expand All @@ -628,6 +630,11 @@ for arg in $@; do
USE_NON_STANDARD_MOUNTPOINTS='TRUE'
shift
;;
--timestamp)
# Add metric timestamp with a leading space to simplify adding
EPOCHTIME=" $(date +%s)"
shift
;;
-h | --help)
# get help
shift
Expand Down Expand Up @@ -665,6 +672,12 @@ if check_cvmfs_version_exact; then
postprocess_metrics_for_2132
fi

# Add timestamp to all metrics if requested
if [[ -n "${EPOCHTIME}" ]]; then
sed "/^#/! s/\$/${EPOCHTIME}/" "${TMPFILE}" > "${TMPFILE}.time"
mv "${TMPFILE}.time" "${TMPFILE}"
fi

if [[ "${HTTP_HEADER}" == 'TRUE' ]]; then
content_length=$(stat --printf="%s" "${TMPFILE}")
echo -ne "HTTP/1.1 200 OK\r\n"
Expand Down