How do you check load average sensibly in a script?
BeginnerScenarioScenarios: health checks, monitoring and alerts
Answer
Situation read → A load of 8 is idle on a 32-core box and overloaded on a 2-core box; compare to CPU count.
What I'd do →
read -r l1 l5 _ < /proc/loadavg
cores=$(nproc)
awk -v l="$l5" -v c="$cores" 'BEGIN {r = l / c; printf "load5 per core: %.2f\n", r; exit !(r > 1.5)}' &&
echo "WARN sustained load above 1.5 per core"
- Use the 5-minute average to ignore short spikes.
- Remember Linux load includes processes in uninterruptible I/O wait (
Dstate), so high load with idle CPU points to storage or NFS.
Why → Normalizing per core makes one threshold work across instance sizes.
Interview tip → Mention the D-state nuance; it shows you understand what load actually measures on Linux.
More on Scenarios: health checks, monitoring and alerts
You are asked for a host health-check script covering disk, memory, systemd services and an HTTP endpoint. How do you design it?IntermediateYour disk alert fires and clears every few minutes around 80%, spamming Slack. How do you fix the alerting?AdvancedA server reports `No space left on device` but `df -h` shows 40% free. What would you add to the health checks?BeginnerAlert when any certificate under `/etc/letsencrypt/live` expires within 21 days.IntermediateA developer wrote a Bash loop that restarts the app whenever its process disappears. What do you suggest instead?IntermediateYou suspect a memory leak in a service. How do you collect evidence with a script before involving developers?Advanced