borg_exporter: get rid of spaces for size
as trailing spaces lead to unparsable textfiles. Additionally add type gauge and fix small shellchecker issues
This commit is contained in:
parent
78957cf17e
commit
c2fedd4886
1 changed files with 11 additions and 7 deletions
|
@ -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"
|
||||
|
|
Loading…
Add table
Reference in a new issue