helper/borg_exporter.sh

28 lines
1,022 B
Bash
Executable file

#!/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