2023-12-02 09:18:19 +01:00
|
|
|
#!/bin/bash
|
|
|
|
{{ ansible_managed | comment }}
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
LOGFILE=/var/log/borg
|
2023-12-02 09:22:32 +01:00
|
|
|
TEXTFILE_COLLECTOR_DIR=/var/lib/prometheus/node-exporter
|
2023-12-02 09:18:19 +01:00
|
|
|
PROM_FILE=$TEXTFILE_COLLECTOR_DIR/backup.prom
|
|
|
|
TMP_FILE=$PROM_FILE.$$
|
|
|
|
HOSTNAME=$(hostname)
|
|
|
|
|
2023-12-02 11:45:43 +01:00
|
|
|
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
|
2023-12-02 09:18:19 +01:00
|
|
|
|
|
|
|
mv $TMP_FILE $PROM_FILE
|