From e18eccc9191ea0cfc979f74b9b1e862101377a05 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Mon, 27 Jan 2025 03:17:21 +0100 Subject: [PATCH] Monitor if no files --- .../rootfs/custom-services.d/30-monitoring.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/birdnet-pi/rootfs/custom-services.d/30-monitoring.sh b/birdnet-pi/rootfs/custom-services.d/30-monitoring.sh index 5b314702192..53f445ce0dc 100755 --- a/birdnet-pi/rootfs/custom-services.d/30-monitoring.sh +++ b/birdnet-pi/rootfs/custom-services.d/30-monitoring.sh @@ -23,6 +23,7 @@ srv="birdnet_recording" srv2="birdnet_analysis" ingest_dir="$RECS_DIR/StreamData" counter=10 +no_files_counter=0 # Ensure directories and permissions mkdir -p "$ingest_dir" chown -R pi:pi "$ingest_dir" @@ -32,6 +33,7 @@ chmod -R 755 "$ingest_dir" apprisealert() { local notification="" local stopped_service="
Stopped services: " + local no_files_alert="${1:-}" # Check for stopped services services=(birdnet_analysis chart_viewer spectrogram_viewer icecast2 birdnet_recording birdnet_log birdnet_stats) @@ -48,6 +50,7 @@ apprisealert() { notification+="
System: ${SITE_NAME:-$(hostname)}" notification+="
Available disk space: $(df -h "$HOME/BirdSongs" | awk 'NR==2 {print $4}')" [[ -n "$BIRDNETPI_URL" ]] && notification+="
Access your BirdNET-Pi" + [[ -n "$no_files_alert" ]] && notification+="
Alert: No files in folder for at least 30 seconds." # Send notification TITLE="BirdNET-Analyzer stopped" @@ -76,6 +79,20 @@ while true; do log_green "$(date) INFO: $wav_count wav files waiting in $ingest_dir, $srv state is $service_state, $srv2 state is $analysis_state" + # Alert if no files in the folder for at least 30 seconds + if ((wav_count == 0)); then + ((no_files_counter++)) + if ((no_files_counter >= 1)); then + log_red "$(date) WARNING: No files in folder for at least 30 seconds" + if [[ -s "$HOME/BirdNET-Pi/apprise.txt" ]]; then + apprisealert "no_files" + fi + no_files_counter=0 + fi + else + no_files_counter=0 + fi + # Pause recorder if queue is too large if ((wav_count > 50)); then log_red "$(date) WARNING: Too many files in queue, pausing $srv and restarting $srv2"