add prometheus exporter rom borg_exporter.sh
This commit is contained in:
parent
c2bc6f2941
commit
78957cf17e
1 changed files with 28 additions and 0 deletions
28
borg_exporter.sh
Executable file
28
borg_exporter.sh
Executable file
|
@ -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
|
Loading…
Add table
Reference in a new issue