You need to alert if "Out of memory" appears more than 50 times in 5 minutes in an app log, without a logging stack. How?
IntermediateScenarioScenarios: health checks, monitoring and alerts
Answer
Situation read → Count matches in a time window. Using the journal or a byte offset avoids rescanning the whole file.
What I'd do →
- If the app logs to journald:
n=$(journalctl -u app --since '5 min ago' --no-pager -o cat | grep -c 'Out of memory' || true) (( n > 50 )) && opskit-alert -s critical -k app-oom -t "app OOM errors" "$n in 5 minutes" - For a file, remember the last byte offset in a state file and read only new data with
tail -c +$((offset + 1)), resetting if the file shrank (rotation). - Run it every 5 minutes from a timer.
Why → Windowed counts give rate-based alerts without Loki or Elasticsearch.
Interview tip → Mention handling rotation (file shrank or inode changed), which is where homemade log watchers break.
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