Users report errors in the last hour. From the Nginx access log, find which endpoints produce the most 5xx responses.
BeginnerScenarioScenarios: text processing and scheduling decisions
Answer
Situation read → Filter by time and status, strip query strings, count per path.
What I'd do →
since=$(date -d '1 hour ago' '+%d/%b/%Y:%H')
awk -v s="$since" '$4 >= "["s && $9 ~ /^5/ {split($7, p, "?"); print $9, p[1]}' /var/log/nginx/access.log |
sort | uniq -c | sort -rn | head -n 15
- Field 9 is the status, field 7 the request path in the combined format.
- Dropping the query string groups
/api/orders?id=1and?id=2together. - The string comparison on
$4works within a single day; for windows across midnight, use epoch conversion orjournalctl --sinceif logs go to the journal.
Why → Grouping by endpoint turns 50,000 error lines into "it is /api/checkout".
Interview tip → Mention checking $upstream_status or upstream response time fields too, to separate nginx errors from backend errors.
More on Scenarios: text processing and scheduling decisions
A MySQL slow log is 3 GB. You need the 10 slowest query patterns. What do you do?IntermediateTwo servers that should be identical behave differently. Compare their installed packages.BeginnerFind which pods were OOMKilled in a namespace, with their container names and restart counts.IntermediateProduce a CSV of running EC2 instances that are missing an `Owner` tag.IntermediateYou have access logs from five web servers and need one timeline sorted by time. How?IntermediateA vendor needs application logs, but they contain emails and card numbers. Mask them first.Intermediate