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"