diff --git a/borg_exporter.sh b/borg_exporter.sh new file mode 100755 index 0000000..3910269 --- /dev/null +++ b/borg_exporter.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +ENVFIILE=/etc/prometheus/node_exporter/borg_exporter.env +[[ -f "$ENVFIILE" ]] && source "$ENVFIILE" + +REPO_BASE=${REPO_BASE:-/home/backup/borg} +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) + +for repository in "${REPOS[@]}" ; do + echo "# $repository" + hostname=${HOSTNAMES[$repository]:-$repository} + if [[ "$hostname" == "$repository" ]] ; then + hostname=${hostname/"${REPO_BASE}/"//} + hostname=${hostname/"/backup"//} + 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 + +mv $TMP_FILE $PROM_FILE