Push metrics to pushgateway
This commit is contained in:
parent
9584fcb9e8
commit
f86c927fc3
5 changed files with 21 additions and 34 deletions
1
Makefile
1
Makefile
|
@ -3,6 +3,7 @@ install:
|
||||||
@cp borg_exporter.sh /usr/local/bin/ \
|
@cp borg_exporter.sh /usr/local/bin/ \
|
||||||
&& chmod +x /usr/local/bin/borg_exporter.sh \
|
&& chmod +x /usr/local/bin/borg_exporter.sh \
|
||||||
&& cp -n borg_exporter.rc /etc/borg_exporter.rc \
|
&& 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.timer /etc/systemd/system/ \
|
||||||
&& cp prometheus-borg-exporter.service /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 _ \
|
&& echo -n "Edit the config file /etc/borg_exporter.rc and press [ENTER] when finished "; read _ \
|
||||||
|
|
11
README.md
11
README.md
|
@ -11,13 +11,6 @@ Export borg information to prometheus.
|
||||||
|
|
||||||
## Install
|
## 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
|
### Manually
|
||||||
Copy `borg_exporter.sh` to `/usr/local/bin`.
|
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.
|
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
|
## Exported metrics
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
BORG_PASSPHRASE=<your-passphrase>
|
BORG_PASSPHRASE=""
|
||||||
REPOSITORY=<your-repository>
|
REPOSITORY=""
|
||||||
|
PUSHGATEWAY_URL=http://pushgateway.clems4ever.com
|
|
@ -2,19 +2,14 @@
|
||||||
|
|
||||||
set -eu
|
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
|
[ -e $TMP_FILE ] && rm -f $TMP_FILE
|
||||||
|
|
||||||
HOSTNAME=$(hostname)
|
HOSTNAME=$(hostname)
|
||||||
ARCHIVES="$(BORG_PASSPHRASE=$BORG_PASSPHRASE borg list $REPOSITORY)"
|
ARCHIVES="$(BORG_PASSPHRASE=$BORG_PASSPHRASE borg list $REPOSITORY)"
|
||||||
COUNTER=0
|
COUNTER=0
|
||||||
|
|
||||||
[ -e $TEXTFILE_COLLECTOR_DIR ] || mkdir -p $TEXTFILE_COLLECTOR_DIR
|
|
||||||
|
|
||||||
COUNTER=$(echo "$ARCHIVES" | wc -l)
|
COUNTER=$(echo "$ARCHIVES" | wc -l)
|
||||||
LAST_ARCHIVE=$(BORG_PASSPHRASE=$BORG_PASSPHRASE borg list --last 1 $REPOSITORY)
|
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_DATE=$(echo $LAST_ARCHIVE | awk '{print $3" "$4}')
|
||||||
LAST_ARCHIVE_TIMESTAMP=$(date -d "$LAST_ARCHIVE_DATE" +"%s")
|
LAST_ARCHIVE_TIMESTAMP=$(date -d "$LAST_ARCHIVE_DATE" +"%s")
|
||||||
CURRENT_DATE="$(date '+%Y-%m-%d %H:%M:%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_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")
|
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_last_archive_timestamp{host=\"${HOSTNAME}\",repository=\"${REPOSITORY}\"} $LAST_ARCHIVE_TIMESTAMP" >> $TMP_FILE
|
||||||
echo "borg_extract_exit_code{host=\"${HOSTNAME}\"} $BORG_EXTRACT_EXIT_CODE" >> $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}\"} $NB_HOUR_FROM_LAST_BCK" >> $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}\"} $COUNTER" >> $TMP_FILE
|
echo "borg_archives_count{host=\"${HOSTNAME}\",repository=\"${REPOSITORY}\"} $COUNTER" >> $TMP_FILE
|
||||||
echo "borg_files_count{host=\"${HOSTNAME}\"} $(echo "$BORG_INFO" | grep "Number of files" | awk '{print $4}')" >> $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}\"} $(echo "$BORG_INFO" | grep "Chunk index" | awk '{print $3}')" >> $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}\"} $(echo "$BORG_INFO" | grep "Chunk index" | awk '{print $4}')" >> $TMP_FILE
|
echo "borg_chunks_total{host=\"${HOSTNAME}\",repository=\"${REPOSITORY}\"} $(echo "$BORG_INFO" | grep "Chunk index" | awk '{print $4}')" >> $TMP_FILE
|
||||||
|
|
||||||
function calc_bytes {
|
function calc_bytes {
|
||||||
NUM=$1
|
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}'))
|
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{host=\"${HOSTNAME}\",repository=\"${REPOSITORY}\"} $LAST_SIZE" >> $TMP_FILE
|
||||||
echo "borg_last_size_compressed{host=\"${HOSTNAME}\"} $LAST_SIZE_COMPRESSED" >> $TMP_FILE
|
echo "borg_last_size_compressed{host=\"${HOSTNAME}\",repository=\"${REPOSITORY}\"} $LAST_SIZE_COMPRESSED" >> $TMP_FILE
|
||||||
echo "borg_last_size_dedup{host=\"${HOSTNAME}\"} $LAST_SIZE_DEDUP" >> $TMP_FILE
|
echo "borg_last_size_dedup{host=\"${HOSTNAME}\",repository=\"${REPOSITORY}\"} $LAST_SIZE_DEDUP" >> $TMP_FILE
|
||||||
echo "borg_total_size{host=\"${HOSTNAME}\"} $TOTAL_SIZE" >> $TMP_FILE
|
echo "borg_total_size{host=\"${HOSTNAME}\",repository=\"${REPOSITORY}\"} $TOTAL_SIZE" >> $TMP_FILE
|
||||||
echo "borg_total_size_compressed{host=\"${HOSTNAME}\"} $TOTAL_SIZE_COMPRESSED" >> $TMP_FILE
|
echo "borg_total_size_compressed{host=\"${HOSTNAME}\",repository=\"${REPOSITORY}\"} $TOTAL_SIZE_COMPRESSED" >> $TMP_FILE
|
||||||
echo "borg_total_size_dedup{host=\"${HOSTNAME}\"} $TOTAL_SIZE_DEDUP" >> $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
|
||||||
|
|
|
@ -4,4 +4,5 @@ After=network-online.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
ExecStart=/usr/local/bin/borg_exporter.sh
|
ExecStart=/usr/local/bin/borg_exporter.sh
|
||||||
|
EnvironmentFile=/etc/borg_exporter.rc
|
||||||
Type=simple
|
Type=simple
|
||||||
|
|
Loading…
Reference in a new issue