From a7207954f83734d20116bddd0a44beea90f223fd Mon Sep 17 00:00:00 2001 From: shmick Date: Wed, 22 Nov 2023 09:26:50 +0200 Subject: [PATCH] Add Prometheus monitoring --- .kumonoboru | 3 +++ kumonoboru.sh | 29 +++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 .kumonoboru diff --git a/.kumonoboru b/.kumonoboru new file mode 100644 index 0000000..64786a5 --- /dev/null +++ b/.kumonoboru @@ -0,0 +1,3 @@ +Gerbil-TK /var/Red-Vol/Media/Pictures +Pukeko-XYZ-Containers /var/Red-Vol/Media/Containers +Pukeko-XYZ-Cloud /var/Red-Vol/Media/Could diff --git a/kumonoboru.sh b/kumonoboru.sh index d3c4c0d..9738258 100755 --- a/kumonoboru.sh +++ b/kumonoboru.sh @@ -44,6 +44,22 @@ flags() } flags "$@" +#File to write results to; picked up by Prometheus and yells about changes +PROM_FILE="$CONTAINER_DIR/prometheus/data/kumonoboru.prom" + +#Remove log from last runs, if present +if [[ -f $PROM_FILE ]]; then + rm $PROM_FILE +fi +## Monitoring codes: +#+ -3 - failed pruning +#+ -2 - failed integrity check +#+ -1 - failed to unlock +#+ 0 - succesfully backed up +#+ 1 - failed backup +#+ 2 - passed integrity check +#+ 3- succesfully pruned + #Defaults if [[ -z $BWLIMIT ]]; then export BWLIMIT="0" @@ -69,7 +85,8 @@ safety(){ #Check no other Restic process is using this repository; Free unnecessary locks, if present if [[ -n $(ps aux | grep restic | grep "$REPOSITORY") ]]; then echo -e "Repository is in use - ignoring" - return 1 + echo "system_backup{name=\"$REPOSITORY\"} -1" >> $PROM_FILE + return 1 # code for ^ failed to unlock # ^ If there's a restic process holding the repository, leave it alone. else echo -e "Repository is not in use - unlocking" @@ -87,8 +104,10 @@ backup(){ echo -e "Backing up repository" "$REPOSITORY" if restic --cache-dir="$RESTIC_CACHE_DIR" -r b2:"$REPOSITORY" backup "$REPOSITORY_PATH" --limit-upload="$BWLIMIT" --limit-download="$BWLIMIT"; then echo -e "$REPOSITORY_PATH" "completed upload to $REPOSITORY." + echo "system_backup{name=\"$REPOSITORY\"} 0" >> $PROM_FILE else echo -e "$REPOSITORY failed to upload path" "$REPOSITORY_PATH" + echo "system_backup{name=\"$REPOSITORY\"} 1" >> $PROM_FILE fi fi } @@ -110,6 +129,9 @@ check(){ restic -r b2:"$REPOSITORY" snapshots | tee -a $LOG else echo -e "Repository failed integrity check - " "$REPOSITORY" + echo "system_backup{name=\"$REPOSITORY\"} -2" >> $PROM_FILE + # code for ^ failed integrity check + fi fi } @@ -125,6 +147,9 @@ clean(){ # Marks repository as cleaned already ^ so it won't passed to this function again. else echo -e "Failed to prune repository" "$REPOSITORY" + echo "system_backup{name=\"$REPOSITORY\"} -3" >> $PROM_FILE + # code for ^ failed pruning + fi fi } @@ -181,4 +206,4 @@ elif [[ -n $REPOSITORY ]] && [[ -n $CLEAN ]]; then fi #Wrap up this run's log and report nicely -echo "All done; have a nice day!" +echo "All done; have a nice day!" \ No newline at end of file