Interview Prep/Shell Scripting/Scenarios: health checks, monitoring and alerts

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"
  1. Use the 5-minute average to ignore short spikes.
  2. Remember Linux load includes processes in uninterruptible I/O wait (D state), 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.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Scenarios: health checks, monitoring and alerts