58 lines
2.2 KiB
Django/Jinja
58 lines
2.2 KiB
Django/Jinja
#!/bin/bash
|
|
{{ ansible_managed | comment }}
|
|
|
|
set -eu
|
|
|
|
TEXTFILE_COLLECTOR_DIR=/var/lib/prometheus/node-exporter
|
|
PROM_FILE=$TEXTFILE_COLLECTOR_DIR/backup.prom
|
|
TMP_FILE=$PROM_FILE.$$
|
|
NOW=$(date +%s)
|
|
BORG_INFO=$(borgmatic --no-color info --last 1 --json)
|
|
|
|
get_field() {
|
|
local query="$1"
|
|
printf '%s' "$BORG_INFO" | jq -r ".[].$query"
|
|
}
|
|
|
|
borg_last_modified=$(get_field 'repository.last_modified' | xargs -I{} date -d "{}" +"%s")
|
|
borg_backup_age=$(echo "$NOW" "$borg_last_modified" | awk '{print(($1 - $2) / (24 * 60 * 60))}')
|
|
|
|
get_status_data() {
|
|
cat <<EOF
|
|
# HELP backup_age Age of last backup ind days.
|
|
# TYPE backup_age gauge
|
|
backup_age $borg_backup_age
|
|
# HELP backup_files Number of files in backup.
|
|
# TYPE backup_files gauge
|
|
backup_files $(get_field 'archives | .[] | .stats.nfiles')
|
|
# HELP backup_chunks_unique Number of unique chunks of recent backup.
|
|
# TYPE backup_chunks_unique gauge
|
|
backup_chunks_unique $(get_field 'cache.stats.total_unique_chunks')
|
|
# HELP backup_chunks_total Number of chunks in all backups.
|
|
# TYPE backup_chunks_total gauge
|
|
backup_chunks_total $(get_field 'cache.stats.total_chunks')
|
|
# HELP backup_last_size Size of last backup in bytes.
|
|
# TYPE backup_last_size gauge
|
|
backup_last_size $(get_field 'archives | .[] | .stats.original_size')
|
|
# HELP backup_last_size_compressed Compressed site of last backup in bytes.
|
|
# TYPE backup_last_size_compressed gauge
|
|
backup_last_size_compressed $(get_field 'archives | .[] | .stats.compressed_size')
|
|
# HELP backup_last_size_dedup Depluplicated size of last backup in bytes.
|
|
# TYPE backup_last_size_dedup gauge
|
|
backup_last_size_dedup $(get_field 'archives | .[] | .stats.deduplicated_size')
|
|
# HELP backup_total_size Size of all backups in bytes.
|
|
# TYPE backup_total_size gauge
|
|
backup_total_size $(get_field 'cache.stats.total_size')
|
|
# HELP backup_total_size_compressed Compressed size of all backups in bytes.
|
|
# TYPE backup_total_size_compressed gauge
|
|
backup_total_size_compressed $(get_field 'cache.stats.total_csize')
|
|
# HELP backup_total_size_dedup Depluplicated size of all backups in bytes.
|
|
# TYPE backup_total_size_dedup gauge
|
|
backup_total_size_dedup $(get_field 'cache.stats.unique_csize')
|
|
EOF
|
|
}
|
|
|
|
status=$(get_status_data)
|
|
|
|
printf '%s' "$status" >"$TMP_FILE"
|
|
mv "$TMP_FILE" "$PROM_FILE"
|