Skip to content

Instantly share code, notes, and snippets.

@uzyn
Last active March 15, 2026 08:29
Show Gist options
  • Select an option

  • Save uzyn/ac3eb010d287245fb87a5f4a3260fcea to your computer and use it in GitHub Desktop.

Select an option

Save uzyn/ac3eb010d287245fb87a5f4a3260fcea to your computer and use it in GitHub Desktop.
Watch server load and notify via ntfy.sh when load is low
#!/bin/bash
# ./watch-load.sh — run this on the server, it will notify you when load drops
# ./watch-load.sh <threshold>, e.g. ./watch-load.sh 1.2 to set threshold to 1.2. Default to 2.0
NTFY_TOPIC="<INSERT NTFY TOPIC>"
THRESHOLD="${1:-2.0}" # first arg, default 2.0; e.g. ./watch_load.sh 1.5
CHECK_INTERVAL=60 # seconds between checks
SUSTAINED_CYCLES=3 # must be low for N consecutive checks before alerting
low_count=0
echo "Watching load average... threshold: <$THRESHOLD for ${SUSTAINED_CYCLES} consecutive checks"
while true; do
LOAD=$(awk '{print $2}' /proc/loadavg) # $2 = 5-min avg, $1 = 1-min, $3 = 15-min
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
echo "[$TIMESTAMP] Load (5m): $LOAD"
if (( $(echo "$LOAD < $THRESHOLD" | bc -l) )); then
(( low_count++ ))
echo " → Low load detected ($low_count/$SUSTAINED_CYCLES)"
else
low_count=0 # reset if load spikes back up
fi
if (( low_count >= SUSTAINED_CYCLES )); then
curl -s \
-H "Title: Server Load is Low ✅" \
-H "Priority: high" \
-H "Tags: bell" \
-d "5-min load: $LOAD (below $THRESHOLD for ${SUSTAINED_CYCLES} checks) | $TIMESTAMP" \
ntfy.sh/$NTFY_TOPIC
echo "Notification sent. Exiting."
break
fi
sleep $CHECK_INTERVAL
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment