mirror of
https://gitlab.archlinux.org/archlinux/infrastructure.git
synced 2025-01-18 08:06:16 +01:00
This was previously monitored as part of the borg text collector, but now that it only runs after each backup (instead of hourly) the stats from monitoring.archlinux.org do not remain accurate for long. Switch back to hourly checks of the storage box's disk usage by adding a new text collector just for this purpose.
40 lines
1.2 KiB
Bash
Executable File
40 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/bash
|
|
|
|
set -o errexit
|
|
set -o nounset
|
|
set -o pipefail
|
|
|
|
if (( $# != 1 )); then
|
|
echo "Missing textcollector directory argument"
|
|
exit 1
|
|
fi
|
|
|
|
TEXTFILE_COLLECTOR_DIR=${1}
|
|
PROM_FILE=$TEXTFILE_COLLECTOR_DIR/borg.prom
|
|
|
|
|
|
TMP_FILE=$PROM_FILE.$$
|
|
[ -e $TMP_FILE ] && rm -f $TMP_FILE
|
|
|
|
trap "rm -f $TMP_FILE" EXIT
|
|
|
|
# Hetzner borg
|
|
if [[ -f /usr/local/bin/borg ]]; then
|
|
LAST_ARCHIVE=$(/usr/local/bin/borg list --last 1)
|
|
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")
|
|
|
|
echo "# HELP borg_hetzner_last_archive_timestamp timestamp of last backup in UTC" >> $TMP_FILE
|
|
echo "# TYPE borg_hetzner_last_archive_timestamp counter" >> $TMP_FILE
|
|
echo "borg_hetzner_last_archive_timestamp $LAST_ARCHIVE_TIMESTAMP" >> $TMP_FILE;
|
|
|
|
REPO_SIZE=$(/usr/local/bin/borg info --json | jq '.cache.stats.unique_csize')
|
|
|
|
echo "# HELP borg_hetzner_repo_size_bytes amount of data stored in the repo in bytes" >> $TMP_FILE
|
|
echo "# TYPE borg_hetzner_repo_size_bytes gauge" >> $TMP_FILE
|
|
echo "borg_hetzner_repo_size_bytes $REPO_SIZE" >> $TMP_FILE
|
|
fi
|
|
|
|
mv -f $TMP_FILE $PROM_FILE
|