From c2fedd4886b414b9625dca4b7540ef8345f9ea46 Mon Sep 17 00:00:00 2001 From: layman Date: Tue, 21 Dec 2021 09:43:57 +0100 Subject: [PATCH] borg_exporter: get rid of spaces for size as trailing spaces lead to unparsable textfiles. Additionally add type gauge and fix small shellchecker issues --- borg_exporter.sh | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/borg_exporter.sh b/borg_exporter.sh index 3910269..c1b9ccb 100755 --- a/borg_exporter.sh +++ b/borg_exporter.sh @@ -9,10 +9,14 @@ TEXTFILE_COLLECTOR_DIR=${TEXTFILE_COLLECTOR_DIR:-/var/lib/node_exporter/} PROM_FILE=$TEXTFILE_COLLECTOR_DIR/backup.prom TMP_FILE=$PROM_FILE.$$ -mapfile -t REPOS < <(find $REPO_BASE -type d -name data -print0 | xargs --null -n1 dirname) +mapfile -t REPOS < <(find "$REPO_BASE" -type d -name data -print0 | xargs --null -n1 dirname) + +if [[ -n "${REPOS[*]}" ]] ; then + echo "# TYPE backup_age_seconds gauge" + echo "# TYPE backup_total_size_bytes gauge" +fi >> "$TMP_FILE" for repository in "${REPOS[@]}" ; do - echo "# $repository" hostname=${HOSTNAMES[$repository]:-$repository} if [[ "$hostname" == "$repository" ]] ; then hostname=${hostname/"${REPO_BASE}/"//} @@ -20,9 +24,9 @@ for repository in "${REPOS[@]}" ; do fi index_base="$repository/index" age_seconds="$(( $(date +%s) - $(date +%s -r "$index_base".*) ))" - size="$(du -s "$repository" | cut -d/ -f1)" - echo backup_age_time_seconds\{host=\""$hostname"\", repository=\""$repository"\"\} "$age_seconds" - echo backup_size_bytes\{host=\""$hostname"\", repository=\""$repository"\"\} "$size" -done >> $TMP_FILE + size="$(du -s "$repository" | cut -f1)" + echo backup_age_seconds\{host=\""$hostname"\",repository=\""$repository"\"\} "$age_seconds" + echo backup_total_size_bytes\{host=\""$hostname"\",repository=\""$repository"\"\} "$size" +done >> "$TMP_FILE" -mv $TMP_FILE $PROM_FILE +mv "$TMP_FILE" "$PROM_FILE"