-
Notifications
You must be signed in to change notification settings - Fork 19
/
borg_exporter
executable file
·67 lines (54 loc) · 2.58 KB
/
borg_exporter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
set -eu
source /etc/borg
TEXTFILE_COLLECTOR_DIR=${COLLECTOR_DIR:-/var/lib/node_exporter/textfile_collector}
PROM_FILE=$TEXTFILE_COLLECTOR_DIR/backup.prom
TMP_FILE=$PROM_FILE.$$
HOSTNAME=$(hostname)
LIST=$(BORG_PASSPHRASE=$BORG_PASSPHRASE borg list "$REPOSITORY" |awk '{print $1}')
COUNTER=0
mkdir -p "$TEXTFILE_COLLECTOR_DIR"
for i in $LIST; do
COUNTER=$((COUNTER+1))
done
BORG_INFO=$(BORG_PASSPHRASE=$BORG_PASSPHRASE borg info "$REPOSITORY::$i")
echo "backup_count{host=\"${HOSTNAME}\"} $COUNTER" > "$TMP_FILE"
{
echo "backup_files{host=\"${HOSTNAME}\"} $(echo "$BORG_INFO" | grep "Number of files" | awk '{print $4}')"
echo "backup_chunks_unique{host=\"${HOSTNAME}\"} $(echo "$BORG_INFO" | grep "Chunk index" | awk '{print $3}')"
echo "backup_chunks_total{host=\"${HOSTNAME}\"} $(echo "$BORG_INFO" | grep "Chunk index" | awk '{print $4}')"
} >> "$TMP_FILE"
function calc_bytes {
NUM=$1
UNIT=$2
case "$UNIT" in
kB)
echo "$NUM" | awk '{ print $1 * 1024 }'
;;
MB)
echo "$NUM" | awk '{ print $1 * 1024 * 1024 }'
;;
GB)
echo "$NUM" | awk '{ print $1 * 1024 * 1024 * 1024 }'
;;
TB)
echo "$NUM" | awk '{ print $1 * 1024 * 1024 * 1024 * 1024 }'
;;
esac
}
# byte size
LAST_SIZE=$(calc_bytes $(echo "$BORG_INFO" |grep "This archive" |awk '{print $3}') $(echo "$BORG_INFO" |grep "This archive" |awk '{print $4}'))
LAST_SIZE_COMPRESSED=$(calc_bytes $(echo "$BORG_INFO" |grep "This archive" |awk '{print $5}') $(echo "$BORG_INFO" |grep "This archive" |awk '{print $6}'))
LAST_SIZE_DEDUP=$(calc_bytes $(echo "$BORG_INFO" |grep "This archive" |awk '{print $7}') $(echo "$BORG_INFO" |grep "This archive" |awk '{print $8}'))
TOTAL_SIZE=$(calc_bytes $(echo "$BORG_INFO" |grep "All archives" |awk '{print $3}') $(echo "$BORG_INFO" |grep "All archives" |awk '{print $4}'))
TOTAL_SIZE_COMPRESSED=$(calc_bytes $(echo "$BORG_INFO" |grep "All archives" |awk '{print $5}') $(echo "$BORG_INFO" |grep "All archives" |awk '{print $6}'))
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{host=\"${HOSTNAME}\"} $LAST_SIZE"
echo "backup_last_size_compressed{host=\"${HOSTNAME}\"} $LAST_SIZE_COMPRESSED"
echo "backup_last_size_dedup{host=\"${HOSTNAME}\"} $LAST_SIZE_DEDUP"
echo "backup_total_size{host=\"${HOSTNAME}\"} $TOTAL_SIZE"
echo "backup_total_size_compressed{host=\"${HOSTNAME}\"} $TOTAL_SIZE_COMPRESSED"
echo "backup_total_size_dedup{host=\"${HOSTNAME}\"} $TOTAL_SIZE_DEDUP"
} >> "$TMP_FILE"
mv "$TMP_FILE" "$PROM_FILE"