Include host label in backup metrics

This commit is contained in:
Julien Pervillé 2017-02-23 10:38:34 +01:00 committed by Timo Derstappen
parent 899d81a630
commit 73c7d8e3ed

View file

@ -7,6 +7,7 @@ source /etc/borg
TEXTFILE_COLLECTOR_DIR=/var/lib/node_exporter/textfile_collector TEXTFILE_COLLECTOR_DIR=/var/lib/node_exporter/textfile_collector
PROM_FILE=$TEXTFILE_COLLECTOR_DIR/backup.prom PROM_FILE=$TEXTFILE_COLLECTOR_DIR/backup.prom
TMP_FILE=$PROM_FILE.$$ TMP_FILE=$PROM_FILE.$$
HOSTNAME=$(hostname)
LIST=$(BORG_PASSPHRASE=$BORG_PASSPHRASE borg list $REPOSITORY |awk '{print $1}') LIST=$(BORG_PASSPHRASE=$BORG_PASSPHRASE borg list $REPOSITORY |awk '{print $1}')
COUNTER=0 COUNTER=0
@ -17,10 +18,10 @@ for i in $LIST; do
done done
BORG_INFO=$(BORG_PASSPHRASE=$BORG_PASSPHRASE borg info "$REPOSITORY::$i") BORG_INFO=$(BORG_PASSPHRASE=$BORG_PASSPHRASE borg info "$REPOSITORY::$i")
echo "backup_count $COUNTER" > $TMP_FILE echo "backup_count{host=\"${HOSTNAME}\"} $COUNTER" > $TMP_FILE
echo "backup_files $(echo "$BORG_INFO" |grep "Number of files" |awk '{print $4}')" >> $TMP_FILE echo "backup_files{host=\"${HOSTNAME}\"} $(echo "$BORG_INFO" | grep "Number of files" | awk '{print $4}')" >> $TMP_FILE
echo "backup_chunks_unique $(echo "$BORG_INFO" |grep "Chunk index" |awk '{print $3}')" >> $TMP_FILE echo "backup_chunks_unique{host=\"${HOSTNAME}\"} $(echo "$BORG_INFO" | grep "Chunk index" | awk '{print $3}')" >> $TMP_FILE
echo "backup_chunks_total $(echo "$BORG_INFO" |grep "Chunk index" |awk '{print $4}')" >> $TMP_FILE echo "backup_chunks_total{host=\"${HOSTNAME}\"} $(echo "$BORG_INFO" | grep "Chunk index" | awk '{print $4}')" >> $TMP_FILE
function calc_bytes { function calc_bytes {
NUM=$1 NUM=$1
@ -51,12 +52,11 @@ TOTAL_SIZE_COMPRESSED=$(calc_bytes $(echo "$BORG_INFO" |grep "All archives" |awk
TOTAL_SIZE_DEDUP=$(calc_bytes $(echo "$BORG_INFO" |grep "All archives" |awk '{print $7}') $(echo "$BORG_INFO" |grep "All archives" |awk '{print $8}')) TOTAL_SIZE_DEDUP=$(calc_bytes $(echo "$BORG_INFO" |grep "All archives" |awk '{print $7}') $(echo "$BORG_INFO" |grep "All archives" |awk '{print $8}'))
echo "backup_last_size $LAST_SIZE" >> $TMP_FILE echo "backup_last_size{host=\"${HOSTNAME}\"} $LAST_SIZE" >> $TMP_FILE
echo "backup_last_size_compressed $LAST_SIZE_COMPRESSED" >> $TMP_FILE echo "backup_last_size_compressed{host=\"${HOSTNAME}\"} $LAST_SIZE_COMPRESSED" >> $TMP_FILE
echo "backup_last_size_dedup $LAST_SIZE_DEDUP" >> $TMP_FILE echo "backup_last_size_dedup{host=\"${HOSTNAME}\"} $LAST_SIZE_DEDUP" >> $TMP_FILE
echo "backup_total_size $TOTAL_SIZE" >> $TMP_FILE echo "backup_total_size{host=\"${HOSTNAME}\"} $TOTAL_SIZE" >> $TMP_FILE
echo "backup_total_size_compressed $TOTAL_SIZE_COMPRESSED" >> $TMP_FILE echo "backup_total_size_compressed{host=\"${HOSTNAME}\"} $TOTAL_SIZE_COMPRESSED" >> $TMP_FILE
echo "backup_total_size_dedup $TOTAL_SIZE_DEDUP" >> $TMP_FILE echo "backup_total_size_dedup{host=\"${HOSTNAME}\"} $TOTAL_SIZE_DEDUP" >> $TMP_FILE
mv $TMP_FILE $PROM_FILE mv $TMP_FILE $PROM_FILE