Skip to content

Commit

Permalink
Monitor if no files
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbelgium authored Jan 27, 2025
1 parent 2dd0c88 commit e18eccc
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions birdnet-pi/rootfs/custom-services.d/30-monitoring.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -32,6 +33,7 @@ chmod -R 755 "$ingest_dir"
apprisealert() {
local notification=""
local stopped_service="<br><b>Stopped services:</b> "
local no_files_alert="${1:-}"

# Check for stopped services
services=(birdnet_analysis chart_viewer spectrogram_viewer icecast2 birdnet_recording birdnet_log birdnet_stats)
Expand All @@ -48,6 +50,7 @@ apprisealert() {
notification+="<br><b>System:</b> ${SITE_NAME:-$(hostname)}"
notification+="<br>Available disk space: $(df -h "$HOME/BirdSongs" | awk 'NR==2 {print $4}')"
[[ -n "$BIRDNETPI_URL" ]] && notification+="<br><a href=\"$BIRDNETPI_URL\">Access your BirdNET-Pi</a>"
[[ -n "$no_files_alert" ]] && notification+="<br><b>Alert:</b> No files in folder for at least 30 seconds."

# Send notification
TITLE="BirdNET-Analyzer stopped"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit e18eccc

Please sign in to comment.