#!/bin/bash {{ ansible_managed | comment }} set -eu LOGFILE=/var/log/borg TEXTFILE_COLLECTOR_DIR=/var/lib/prometheus/node-exporter PROM_FILE=$TEXTFILE_COLLECTOR_DIR/backup.prom TMP_FILE=$PROM_FILE.$$ HOSTNAME=$(hostname) BORG_INFO=$(borgmatic --no-color info --last 1 --json ) || mv $TMP_FILE $PROM_FILE echo "backup_last_run{host=\"${HOSTNAME}\"} $(echo "$BORG_INFO" | jq -r .[].repository.last_modified)" >> $TMP_FILE echo "backup_files{host=\"${HOSTNAME}\"} $(echo "$BORG_INFO" | jq -r '.[].archives | .[] | .stats.nfiles')" >> $TMP_FILE echo "backup_chunks_unique{host=\"${HOSTNAME}\"} $(echo "$BORG_INFO" | jq -r '.[] | .cache.stats.total_unique_chunks')" >> $TMP_FILE echo "backup_chunks_total{host=\"${HOSTNAME}\"} $(echo "$BORG_INFO" | jq -r '.[] | .cache.stats.total_chunks')" >> $TMP_FILE echo "backup_last_size{host=\"${HOSTNAME}\"} $(echo "$BORG_INFO" | jq -r '.[].archives | .[] | .stats.original_size')" >> $TMP_FILE echo "backup_last_size_compressed{host=\"${HOSTNAME}\"} $(echo "$BORG_INFO" | jq -r '.[].archives | .[] | .stats.compressed_size')" >> $TMP_FILE echo "backup_last_size_dedup{host=\"${HOSTNAME}\"} $(echo "$BORG_INFO" | jq -r '.[].archives | .[] | .stats.deduplicated_size')" >> $TMP_FILE echo "backup_total_size{host=\"${HOSTNAME}\"} $(echo "$BORG_INFO" |j q -r '.[] | .cache.stats.total_size')" >> $TMP_FILE echo "backup_total_size_compressed{host=\"${HOSTNAME}\"} $(echo "$BORG_INFO" | jq -r '.[] | .cache.stats.total_csize')" >> $TMP_FILE echo "backup_total_size_dedup{host=\"${HOSTNAME}\"} $(echo "$BORG_INFO" | jq -r '.[] | .cache.stats.unique_csize')" >> $TMP_FILE mv $TMP_FILE $PROM_FILE