diff --git a/Makefile b/Makefile index 62c67ef..63b60da 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ install: @cp borg_exporter.sh /usr/local/bin/ \ && chmod +x /usr/local/bin/borg_exporter.sh \ && cp -n borg_exporter.rc /etc/borg_exporter.rc \ + && chmod 700 /etc/borg_exporter.rc \ && cp prometheus-borg-exporter.timer /etc/systemd/system/ \ && cp prometheus-borg-exporter.service /etc/systemd/system/ \ && echo -n "Edit the config file /etc/borg_exporter.rc and press [ENTER] when finished "; read _ \ diff --git a/README.md b/README.md index f28ad19..2ffa43c 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,6 @@ Export borg information to prometheus. ## Install -You must install this node exporter in each host that you want to monitor. - -### With the Makefile - -For convenience, you can install this exporter with the command line -`make install` or follow the process described in the next paragraph. - ### Manually Copy `borg_exporter.sh` to `/usr/local/bin`. @@ -32,10 +25,6 @@ systemctl start prometheus-borg-exporter.timer Alternative: Use `ExecStartPost` in your borg backupt timer itself to write our the metrics. -## Configure your node exporter - -You must start the node exporter service with the following parameter: `--collector.textfile.directory=/var/lib/node_exporter/textfile_collector` - ## Exported metrics ``` diff --git a/borg_exporter.rc b/borg_exporter.rc index b27d353..f728547 100644 --- a/borg_exporter.rc +++ b/borg_exporter.rc @@ -1,2 +1,3 @@ -BORG_PASSPHRASE= -REPOSITORY= +BORG_PASSPHRASE="" +REPOSITORY="" +PUSHGATEWAY_URL=http://pushgateway.clems4ever.com \ No newline at end of file diff --git a/borg_exporter.sh b/borg_exporter.sh index 2841a6f..4b399a5 100755 --- a/borg_exporter.sh +++ b/borg_exporter.sh @@ -2,19 +2,14 @@ set -eu -source /etc/borg_exporter.rc +TMP_FILE=$(mktemp) -TEXTFILE_COLLECTOR_DIR=/var/lib/node_exporter/textfile_collector -PROM_FILE=$TEXTFILE_COLLECTOR_DIR/bork.prom - -TMP_FILE=$PROM_FILE.$$ [ -e $TMP_FILE ] && rm -f $TMP_FILE HOSTNAME=$(hostname) ARCHIVES="$(BORG_PASSPHRASE=$BORG_PASSPHRASE borg list $REPOSITORY)" COUNTER=0 -[ -e $TEXTFILE_COLLECTOR_DIR ] || mkdir -p $TEXTFILE_COLLECTOR_DIR COUNTER=$(echo "$ARCHIVES" | wc -l) LAST_ARCHIVE=$(BORG_PASSPHRASE=$BORG_PASSPHRASE borg list --last 1 $REPOSITORY) @@ -22,18 +17,18 @@ LAST_ARCHIVE_NAME=$(echo $LAST_ARCHIVE | awk '{print $1}') LAST_ARCHIVE_DATE=$(echo $LAST_ARCHIVE | awk '{print $3" "$4}') LAST_ARCHIVE_TIMESTAMP=$(date -d "$LAST_ARCHIVE_DATE" +"%s") CURRENT_DATE="$(date '+%Y-%m-%d %H:%M:%S')" -NB_HOUR_FROM_LAST_BCK=$(dateutils.ddiff "$LAST_ARCHIVE_DATE" "$CURRENT_DATE" -f '%H') +NB_HOUR_FROM_LAST_BCK=$(datediff "$LAST_ARCHIVE_DATE" "$CURRENT_DATE" -f '%H') BORG_EXTRACT_EXIT_CODE=$(BORG_PASSPHRASE="$BORG_PASSPHRASE" borg extract --dry-run "$REPOSITORY::$LAST_ARCHIVE_NAME" > /dev/null 2>&1; echo $?) BORG_INFO=$(BORG_PASSPHRASE="$BORG_PASSPHRASE" borg info "$REPOSITORY::$LAST_ARCHIVE_NAME") -echo "borg_last_archive_timestamp{host=\"${HOSTNAME}\"} $LAST_ARCHIVE_TIMESTAMP" >> $TMP_FILE -echo "borg_extract_exit_code{host=\"${HOSTNAME}\"} $BORG_EXTRACT_EXIT_CODE" >> $TMP_FILE -echo "borg_hours_from_last_archive{host=\"${HOSTNAME}\"} $NB_HOUR_FROM_LAST_BCK" >> $TMP_FILE -echo "borg_archives_count{host=\"${HOSTNAME}\"} $COUNTER" >> $TMP_FILE -echo "borg_files_count{host=\"${HOSTNAME}\"} $(echo "$BORG_INFO" | grep "Number of files" | awk '{print $4}')" >> $TMP_FILE -echo "borg_chunks_unique{host=\"${HOSTNAME}\"} $(echo "$BORG_INFO" | grep "Chunk index" | awk '{print $3}')" >> $TMP_FILE -echo "borg_chunks_total{host=\"${HOSTNAME}\"} $(echo "$BORG_INFO" | grep "Chunk index" | awk '{print $4}')" >> $TMP_FILE +echo "borg_last_archive_timestamp{host=\"${HOSTNAME}\",repository=\"${REPOSITORY}\"} $LAST_ARCHIVE_TIMESTAMP" >> $TMP_FILE +echo "borg_extract_exit_code{host=\"${HOSTNAME}\",repository=\"${REPOSITORY}\"} $BORG_EXTRACT_EXIT_CODE" >> $TMP_FILE +echo "borg_hours_from_last_archive{host=\"${HOSTNAME}\",repository=\"${REPOSITORY}\"} $NB_HOUR_FROM_LAST_BCK" >> $TMP_FILE +echo "borg_archives_count{host=\"${HOSTNAME}\",repository=\"${REPOSITORY}\"} $COUNTER" >> $TMP_FILE +echo "borg_files_count{host=\"${HOSTNAME}\",repository=\"${REPOSITORY}\"} $(echo "$BORG_INFO" | grep "Number of files" | awk '{print $4}')" >> $TMP_FILE +echo "borg_chunks_unique{host=\"${HOSTNAME}\",repository=\"${REPOSITORY}\"} $(echo "$BORG_INFO" | grep "Chunk index" | awk '{print $3}')" >> $TMP_FILE +echo "borg_chunks_total{host=\"${HOSTNAME}\",repository=\"${REPOSITORY}\"} $(echo "$BORG_INFO" | grep "Chunk index" | awk '{print $4}')" >> $TMP_FILE function calc_bytes { NUM=$1 @@ -64,11 +59,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}')) -echo "borg_last_size{host=\"${HOSTNAME}\"} $LAST_SIZE" >> $TMP_FILE -echo "borg_last_size_compressed{host=\"${HOSTNAME}\"} $LAST_SIZE_COMPRESSED" >> $TMP_FILE -echo "borg_last_size_dedup{host=\"${HOSTNAME}\"} $LAST_SIZE_DEDUP" >> $TMP_FILE -echo "borg_total_size{host=\"${HOSTNAME}\"} $TOTAL_SIZE" >> $TMP_FILE -echo "borg_total_size_compressed{host=\"${HOSTNAME}\"} $TOTAL_SIZE_COMPRESSED" >> $TMP_FILE -echo "borg_total_size_dedup{host=\"${HOSTNAME}\"} $TOTAL_SIZE_DEDUP" >> $TMP_FILE +echo "borg_last_size{host=\"${HOSTNAME}\",repository=\"${REPOSITORY}\"} $LAST_SIZE" >> $TMP_FILE +echo "borg_last_size_compressed{host=\"${HOSTNAME}\",repository=\"${REPOSITORY}\"} $LAST_SIZE_COMPRESSED" >> $TMP_FILE +echo "borg_last_size_dedup{host=\"${HOSTNAME}\",repository=\"${REPOSITORY}\"} $LAST_SIZE_DEDUP" >> $TMP_FILE +echo "borg_total_size{host=\"${HOSTNAME}\",repository=\"${REPOSITORY}\"} $TOTAL_SIZE" >> $TMP_FILE +echo "borg_total_size_compressed{host=\"${HOSTNAME}\",repository=\"${REPOSITORY}\"} $TOTAL_SIZE_COMPRESSED" >> $TMP_FILE +echo "borg_total_size_dedup{host=\"${HOSTNAME}\",repository=\"${REPOSITORY}\"} $TOTAL_SIZE_DEDUP" >> $TMP_FILE -mv -f $TMP_FILE $PROM_FILE +cat $TMP_FILE | curl --data-binary @- ${PUSHGATEWAY_URL}/metrics/job/borg-exporter diff --git a/prometheus-borg-exporter.service b/prometheus-borg-exporter.service index 2830532..8116cc2 100644 --- a/prometheus-borg-exporter.service +++ b/prometheus-borg-exporter.service @@ -4,4 +4,5 @@ After=network-online.target [Service] ExecStart=/usr/local/bin/borg_exporter.sh +EnvironmentFile=/etc/borg_exporter.rc Type=simple