Add Prometheus monitoring

This commit is contained in:
2023-11-22 09:26:50 +02:00
parent 405b328ddb
commit a7207954f8
2 changed files with 30 additions and 2 deletions

3
.kumonoboru Normal file
View File

@@ -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

View File

@@ -44,6 +44,22 @@ flags()
} }
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 #Defaults
if [[ -z $BWLIMIT ]]; then if [[ -z $BWLIMIT ]]; then
export BWLIMIT="0" export BWLIMIT="0"
@@ -69,7 +85,8 @@ safety(){
#Check no other Restic process is using this repository; Free unnecessary locks, if present #Check no other Restic process is using this repository; Free unnecessary locks, if present
if [[ -n $(ps aux | grep restic | grep "$REPOSITORY") ]]; then if [[ -n $(ps aux | grep restic | grep "$REPOSITORY") ]]; then
echo -e "Repository is in use - ignoring" 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. # ^ If there's a restic process holding the repository, leave it alone.
else else
echo -e "Repository is not in use - unlocking" echo -e "Repository is not in use - unlocking"
@@ -87,8 +104,10 @@ backup(){
echo -e "Backing up repository" "$REPOSITORY" 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 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 -e "$REPOSITORY_PATH" "completed upload to $REPOSITORY."
echo "system_backup{name=\"$REPOSITORY\"} 0" >> $PROM_FILE
else else
echo -e "$REPOSITORY failed to upload path" "$REPOSITORY_PATH" echo -e "$REPOSITORY failed to upload path" "$REPOSITORY_PATH"
echo "system_backup{name=\"$REPOSITORY\"} 1" >> $PROM_FILE
fi fi
fi fi
} }
@@ -110,6 +129,9 @@ check(){
restic -r b2:"$REPOSITORY" snapshots | tee -a $LOG restic -r b2:"$REPOSITORY" snapshots | tee -a $LOG
else else
echo -e "Repository failed integrity check - " "$REPOSITORY" echo -e "Repository failed integrity check - " "$REPOSITORY"
echo "system_backup{name=\"$REPOSITORY\"} -2" >> $PROM_FILE
# code for ^ failed integrity check
fi fi
fi fi
} }
@@ -125,6 +147,9 @@ clean(){
# Marks repository as cleaned already ^ so it won't passed to this function again. # Marks repository as cleaned already ^ so it won't passed to this function again.
else else
echo -e "Failed to prune repository" "$REPOSITORY" echo -e "Failed to prune repository" "$REPOSITORY"
echo "system_backup{name=\"$REPOSITORY\"} -3" >> $PROM_FILE
# code for ^ failed pruning
fi fi
fi fi
} }