notify-prom-stats.sh 1.2 KB

123456789101112131415161718192021222324252627282930
  1. #!/bin/bash
  2. # Exit if no Prometheus Pushgateway URL is defined
  3. [ -z "$PROM_URL" ] && exit
  4. # Get latest backup status as json
  5. json=`borg info --last 1 --json`
  6. # Parse json in the Prometheus exposition formatand and transmit
  7. cat <<EOF | curl --data-binary @- $PROM_URL
  8. # TYPE borg_run_duration_seconds gauge
  9. # HELP borg_run_duration_seconds duration between start and end
  10. `echo -n 'borg_run_duration_seconds ' && \
  11. echo $json | grep -o '"duration": [0-9]*' | grep -o '[0-9]*'`
  12. # TYPE borg_run_size_deduplicated_bytes gauge
  13. # HELP borg_run_size_deduplicated_bytes deduplicated size of the last run
  14. `echo -n 'borg_run_size_deduplicated_bytes ' && \
  15. echo $json | grep -o '"compressed_size": [0-9]*' | grep -o '[0-9]*'`
  16. # TYPE borg_run_size_original_bytes gauge
  17. # HELP borg_run_size_original_bytes original size of the last run
  18. `echo -n 'borg_run_size_original_bytes ' && \
  19. echo $json | grep -o '"original_size": [0-9]*' | grep -o '[0-9]*'`
  20. # TYPE borg_cache_chunks_size_total_compressed_bytes gauge
  21. # HELP borg_cache_chunks_size_total_compressed_bytes total size of all chunks
  22. `echo -n 'borg_cache_chunks_size_total_compressed_bytes ' && \
  23. echo $json | grep -o '"unique_csize": [0-9]*' | grep -o '[0-9]*'`
  24. EOF