Uptime monitoring from outside your own infrastructure that alerts you the minute your site goes down — upordown.online
Every postmortem starts with a timeline, and every timeline starts with an argument. "It went down around 14:10." "No, I saw errors at 14:02." "The alert came at 14:15, so that's when it started."
Your access log settles it. Every request has a timestamp and a status code. If you count them per minute, the shape of the outage appears: the moment 5xx responses spike, the minutes where traffic simply stopped arriving, and the long tail where things were "mostly back" but not quite.
This post shows two ways to do it: a one-liner with awk for when you're on the server in the middle of things, and a Python script for the postmortem.
The log format
The examples assume Nginx's default combined format:
203.0.113.7 - - [16/Nov/2026:14:02:13 +0000] "GET /checkout HTTP/2.0" 502 157 "-" "Mozilla/5.0 ..."
The timestamp is the fourth field (with a leading [), and the status code is the ninth when you split on spaces. If you use a custom format or JSON logs, adjust the field numbers; the idea is the same.
The quick version: awk
Requests and 5xx errors per minute:
awk '{
minute = substr($4, 2, 17) # 16/Nov/2026:14:02
total[minute]++
if ($9 ~ /^5/) err[minute]++
} END {
for (m in total) printf "%s %6d %6d\n", m, total[m], err[m]
}' /var/log/nginx/access.log | sort
Output looks like:
16/Nov/2026:14:00 1204 2
16/Nov/2026:14:01 1188 1
16/Nov/2026:14:02 973 611
16/Nov/2026:14:03 402 398
16/Nov/2026:14:04 37 37
16/Nov/2026:14:05 12 12
...
16/Nov/2026:14:21 1120 48
16/Nov/2026:14:22 1197 3
That's the outage. It started at 14:02, not 14:10. And notice what happened at 14:04: total requests collapsed. That doesn't mean users stopped coming. It means requests stopped reaching Nginx at all, or Nginx stopped being able to log them. Which brings up the most important point in this post.
Missing requests are part of the outage
An access log only contains requests that reached the server and finished. If the server was down, overloaded, unreachable, or a load balancer in front of it was failing, those requests are simply absent. A per-minute count that drops to near zero is as much an outage signal as a wall of 502s.
So always look at two columns: errors, and total traffic compared to a normal minute. The script below does that explicitly.
The postmortem version: Python
#!/usr/bin/env python3
"""Per-minute traffic and error summary from an Nginx combined log."""
import re, sys
from collections import Counter
from datetime import datetime
LINE = re.compile(r'\[(\d{2}/\w{3}/\d{4}:\d{2}:\d{2}):\d{2} [^\]]+\] "[^"]*" (\d{3})')
total, errors = Counter(), Counter()
for path in sys.argv[1:]:
with open(path, errors="replace") as f:
for line in f:
m = LINE.search(line)
if not m:
continue
minute = datetime.strptime(m.group(1), "%d/%b/%Y:%H:%M")
total[minute] += 1
if m.group(2).startswith("5"):
errors[minute] += 1
minutes = sorted(total)
normal = sorted(total.values())[len(total) // 2] # median requests per minute
print(f"median requests/minute: {normal}")
for m in minutes:
t, e = total[m], errors[m]
bad = e / t > 0.05 or t < normal * 0.3
flag = " <-- " + ("errors" if e / t > 0.05 else "traffic drop") if bad else ""
print(f"{m:%Y-%m-%d %H:%M} {t:6d} {e:6d}{flag}")
Run it over the rotated logs too:
python3 outage_minutes.py /var/log/nginx/access.log.1 /var/log/nginx/access.log
The script flags any minute where more than 5% of requests failed, or where traffic dropped below 30% of a normal minute. The first flagged minute is when the outage started from the server's point of view. The last flagged minute before a run of clean ones is when it really ended, which is often several minutes after somebody declared it resolved.
One caveat: minutes with zero requests don't appear at all, because there's nothing to count. If you see the timestamps jump from 14:04 to 14:11, those seven missing minutes are the worst part of the outage.
Your log can only describe the requests that reached you. upordown.online checks the site from outside, so for the minutes where the log goes silent you still have a record of what visitors got, and an alert at the start rather than a reconstruction afterwards.
Splitting by URL and status
Once you know the window, narrow it down. Which paths failed, and with which codes?
awk '$4 >= "[16/Nov/2026:14:02" && $4 < "[16/Nov/2026:14:23" && $9 ~ /^5/ {print $9, $7}' \
/var/log/nginx/access.log | sort | uniq -c | sort -rn | head -20
String comparison on the timestamp works here because both sides share the same date. For a window spanning midnight, use the Python script and filter by datetime.
This often reveals that "the site was down" really meant "every request to /api/ returned 502 because one upstream died, and static pages were fine", which is a very different postmortem.
Timezones and clocks
Nginx logs in the server's local time with an explicit offset. Your alerting tool, chat messages and the cloud provider's status page may all use different zones. Before you build a timeline, convert everything to one zone (UTC is easiest) and write the zone in the postmortem. Half of all "the alert was 2 hours late" confusion is a timezone.
What to keep
After the postmortem, keep the script in your runbook repository. Next time, the timeline takes two minutes instead of an argument. And compare its start time with when your first alert fired: the gap between them is the number your monitoring should be trying to shrink.
Related reading
- Should your uptime monitor page you when the site is slow, or only when it's down? Let's argue about it
- Your site is down and the logs are 4 GB: 7 tools for reading them fast
- Two developers, one outage, no postmortem? That's how the same outage happens again
- How to fix 502 Bad Gateway in Nginx: find the error log line that tells you why
How do you build incident timelines today: logs, monitoring graphs, or memory and chat history? And have the logs ever disagreed with what everyone remembered?
Top comments (0)