notify-prom-status.sh 529 B

12345678910111213141516171819
  1. #!/bin/bash
  2. # Exit if no Pushgateway URL is defined
  3. [ -z "$PROM_URL" ] && exit
  4. case $1 in
  5. start) state='1'; status='started' ;;
  6. stop|0) state='0'; status='stopped' ;;
  7. info|1) state='0'; status='stopped with info' ;;
  8. fail|2|*) state='-1'; status='failed' ;;
  9. esac
  10. cat <<EOF | curl --data-binary @- $PROM_URL
  11. # TYPE borg_hook_state gauge
  12. # HELP borg_hook_state 1=started 0=stopped -1=failed
  13. borg_hook_state $state
  14. # TYPE borg_hook_state_timestamp gauge
  15. borg_hook_state_timestamp{label="$status"} `date +%s`
  16. EOF