The health-check script itself started hanging, and cron has 30 copies running. What happened and how do you harden it?
AdvancedScenarioScenarios: health checks, monitoring and alerts
Answer
Situation read → A check blocked forever, most likely df or stat on a hung NFS mount, or a curl without a timeout, and cron kept starting new copies.
What I'd do →
- Find what blocks:
ps -eo pid,stat,wchan:30,cmd | grep -E 'health|df'(stateDonnfspoints at the mount). - Bound every external call:
timeout 10 df -P,curl --max-time 5,ssh -o ConnectTimeout=5. - Skip network filesystems in disk checks (
df -lor-x nfs -x nfs4 -x cifs) and check them separately with a timeout. - Add a single-instance lock (
flock -n) and an overalltimeoutin the scheduler (TimeoutStartSec=in systemd). - Report a hung check as UNKNOWN or CRITICAL instead of hanging.
Why → A monitoring script that hangs both hides problems and adds load during an incident.
Interview tip → Say "every external call gets a timeout" as a rule you always follow.
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