Skip to main content

Linux and servers · Intermediate · 20 min

Find the cause of an outage in your server logs

By Padding · Updated 18 Nov 2026
Ubuntu 26.04.1 LTS

You will know which Ubuntu log holds what, and you will work through a practice incident to a timeline, a likely cause and a saved, checksummed evidence folder.

On this page

When a site goes down, the logs usually already say why. The difficulty is that the story is spread across five or six files, each with its own timestamp format, and the loudest file is often not the one that holds the cause. This tutorial gives you a map of where Ubuntu writes things, then a drill: a practice set of logs from a shop API that returned 502 errors for four minutes while someone was guessing SSH passwords. You will measure the outage, check whether it is new, look at who was affected, build one timeline across files, and save the evidence so someone else can check your work.

Every command in the drill reads files under ~/outage-drill, so you need no sudo for it and you cannot damage anything. Each step also shows the same command for the real files under /var/log.

Work in this order during a real incident: measure the symptom, find when it started and stopped, line up everything else that happened in that window, then decide. Resist reading the first scary line and stopping there.

Step 1 · Learn where Ubuntu writes each kind of log

Ubuntu has two layers. The systemd journal collects messages from the kernel and every service. If rsyslog is installed, it copies those messages into plain text files under /var/log, which is what grep and awk are good at. Check which you have:

Bash
systemctl is-active rsyslog
timedatectl

If the first command prints active, the text files below exist. If it prints inactive or the unit is not found, the same messages are only in the journal: read kernel messages with journalctl -k, SSH with journalctl -u ssh and a service with journalctl -u <name>. The journal is covered in /tutorials/search-the-systemd-journal-with-journalctl.

timedatectl shows the server's time zone. Note it before you compare files: a server on Africa/Lagos writes nginx times with +0100, so an alert sent in UTC appears an hour earlier than the matching log lines. Many teams set servers to UTC for this reason.

The files you will use most:

  • /var/log/syslog: most system messages, including the kernel and systemd's view of services starting, failing and restarting. Logins and sudo are left out.
  • /var/log/auth.log: SSH logins, failed passwords and every sudo command.
  • /var/log/kern.log: kernel messages only, such as the out-of-memory (OOM) killer, disk errors and firewall drops. They also appear in syslog.
  • /var/log/nginx/access.log and /var/log/nginx/error.log: one line per request, and nginx's own problems, such as failing to reach the app behind it.
  • /var/log/apt/history.log and /var/log/dpkg.log: what was installed or upgraded, when and by whom. A change just before an outage is always worth a look.

logrotate renames old files rather than deleting them at once: auth.log.1 is the previous period, and auth.log.2.gz and older are compressed. On current Ubuntu releases, rsyslog writes timestamps something like 2026-11-18T14:03:04.512301+00:00; if your server shows the older Nov 18 14:03:04 style, the substr lengths in the timeline script later need changing to match.

List what your server keeps and check the clock:

Bash
ls /var/log
date -u

Check it worked

You can name the file you would open first for each of these: a failed SSH login, a service killed for using too much memory, a burst of 502 errors, and a package upgraded last night.

Step 2 · Create the practice logs

The script below writes a small incident to ~/outage-drill/log, laid out like /var/log. The traffic and events are made up, with addresses from the ranges reserved for documentation. Create a folder and the script:

Bash
mkdir -p ~/outage-drill
cat > ~/outage-drill/make-drill-logs.sh <<'DRILL'
#!/usr/bin/env bash
# Writes a practice set of logs for one incident on 18 Nov 2026, laid out like /var/log.
set -euo pipefail
out=${1:?usage: make-drill-logs.sh DIR}
mkdir -p "$out/nginx" "$out/apt"

# nginx access log, 14:00:00-14:09:59: one request a second, plus a crawler every third second
awk 'BEGIN {
  split("/ /api/orders /api/cart /static/app.js", path, " ")
  for (s = 0; s < 600; s++) {
    ts = sprintf("18/Nov/2026:14:%02d:%02d +0000", int(s / 60), s % 60)
    st = (s >= 185 && s < 425) ? 502 : (s % 53 == 0 ? 404 : 200)
    by = (st == 502) ? 157 : (st == 404 ? 153 : 1200 + s % 500)
    printf "198.51.100.%d - - [%s] \"GET %s HTTP/1.1\" %d %d \"-\" \"Mozilla/5.0\"\n", 10 + s % 7, ts, path[s % 4 + 1], st, by
    if (s % 3 == 0)
      printf "192.0.2.77 - - [%s] \"GET /api/products HTTP/1.1\" %d %d \"-\" \"catalog-sync/1.4\"\n", ts, st, by
  }
}' > "$out/nginx/access.log"

# nginx error log: one upstream error for every 502 above
awk '$9 == 502 {
  split($4, t, ":")
  printf "2026/11/18 %s:%s:%s [error] 812#812: *%d connect() failed (111: Connection refused) while connecting to upstream, client: %s, server: shop.example.com, request: \"GET %s HTTP/1.1\", upstream: \"http://127.0.0.1:3000%s\", host: \"shop.example.com\"\n", t[2], t[3], substr(t[4], 1, 2), 1000 + NR, $1, $7, $7
}' "$out/nginx/access.log" > "$out/nginx/error.log"

# Older access logs: yesterday (rotated, not yet compressed) and the day before (compressed)
awk 'BEGIN { for (s = 0; s < 600; s += 5) printf "198.51.100.%d - - [17/Nov/2026:14:%02d:%02d +0000] \"GET / HTTP/1.1\" %d 1400 \"-\" \"Mozilla/5.0\"\n", 10 + s % 7, int(s / 60), s % 60, (s == 300 ? 404 : 200) }' > "$out/nginx/access.log.1"
awk 'BEGIN { for (s = 0; s < 600; s += 5) printf "198.51.100.%d - - [16/Nov/2026:14:%02d:%02d +0000] \"GET / HTTP/1.1\" %d 1400 \"-\" \"Mozilla/5.0\"\n", 10 + s % 7, int(s / 60), s % 60, (s == 200 || s == 350 || s == 500 ? 502 : 200) }' | gzip -n > "$out/nginx/access.log.2.gz"

# auth.log: a deploy login, sudo, a password-guessing run, then the restart
{
  echo "2026-11-18T13:58:10.204118+00:00 web1 sshd-session[1874]: Accepted publickey for deploy from 198.51.100.200 port 50122 ssh2: ED25519 SHA256:k3Vq0nYhX2bWm9dPpL7sT1uA4cE8fG6hJ5iK0lM2nO8"
  echo "2026-11-18T14:02:09.771520+00:00 web1 sudo:   deploy : TTY=pts/0 ; PWD=/home/deploy ; USER=root ; COMMAND=/usr/bin/apt install ./shop-api_2.5.0_all.deb"
  awk 'BEGIN { split("admin test oracle guest", u, " ")
    for (i = 0; i < 60; i++) { s = 60 + i * 4
      printf "2026-11-18T14:%02d:%02d.%06d+00:00 web1 sshd-session[%d]: Failed password for invalid user %s from 203.0.113.45 port %d ssh2\n", int(s / 60), s % 60, 100000 + i * 7919, 2100 + i, u[i % 4 + 1], 40000 + i * 13 } }'
  echo "2026-11-18T14:06:40.118302+00:00 web1 sshd-session[2330]: Accepted publickey for deploy from 198.51.100.200 port 50188 ssh2: ED25519 SHA256:k3Vq0nYhX2bWm9dPpL7sT1uA4cE8fG6hJ5iK0lM2nO8"
  echo "2026-11-18T14:07:03.402911+00:00 web1 sudo:   deploy : TTY=pts/1 ; PWD=/home/deploy ; USER=root ; COMMAND=/usr/bin/systemctl restart shop.service"
} > "$out/auth.log"
awk 'BEGIN { for (i = 0; i < 6; i++) printf "2026-11-16T03:12:%02d.500000+00:00 web1 sshd-session[%d]: Failed password for invalid user admin from 203.0.113.45 port %d ssh2\n", i * 5, 900 + i, 51000 + i }' | gzip -n > "$out/auth.log.2.gz"

# Kernel messages: the OOM killer ends the app
cat > "$out/kern.log" <<'KERN'
2026-11-18T13:41:22.009113+00:00 web1 kernel: workqueue: drm_fb_helper_damage_work hogged CPU for >10000us 4 times, consider switching to WQ_UNBOUND
2026-11-18T14:03:04.512301+00:00 web1 kernel: node invoked oom-killer: gfp_mask=0x140cca(GFP_HIGHUSER_MOVABLE|__GFP_COMP), order=0, oom_score_adj=0
2026-11-18T14:03:04.512388+00:00 web1 kernel: oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,global_oom,task_memcg=/system.slice/shop.service,task=node,pid=2211,uid=998
2026-11-18T14:03:04.512402+00:00 web1 kernel: Out of memory: Killed process 2211 (node) total-vm:2843120kB, anon-rss:1903344kB, file-rss:0kB, shmem-rss:0kB, UID:998 pgtables:4212kB oom_score_adj:0
KERN

# syslog: everything except auth, so it repeats the kernel lines and adds systemd's view
{
  echo "2026-11-18T13:55:00.100231+00:00 web1 systemd[1]: Starting sysstat-collect.service - system activity accounting tool..."
  grep '14:03:04' "$out/kern.log"
  echo "2026-11-18T14:03:04.690217+00:00 web1 systemd[1]: shop.service: A process of this unit has been killed by the OOM killer."
  echo "2026-11-18T14:03:04.702455+00:00 web1 systemd[1]: shop.service: Main process exited, code=killed, status=9/KILL"
  echo "2026-11-18T14:03:04.702530+00:00 web1 systemd[1]: shop.service: Failed with result 'oom-kill'."
  echo "2026-11-18T14:07:03.911846+00:00 web1 systemd[1]: Started shop.service - Shop API."
} > "$out/syslog"

# Package changes
cat > "$out/dpkg.log" <<'DPKG'
2026-11-18 14:02:12 startup archives unpack
2026-11-18 14:02:12 upgrade shop-api:all 2.4.0 2.5.0
2026-11-18 14:02:12 status half-configured shop-api:all 2.4.0
2026-11-18 14:02:13 status unpacked shop-api:all 2.5.0
2026-11-18 14:02:13 configure shop-api:all 2.5.0 <none>
2026-11-18 14:02:13 status installed shop-api:all 2.5.0
DPKG
printf 'Start-Date: 2026-11-18  14:02:10\nCommandline: apt install ./shop-api_2.5.0_all.deb\nRequested-By: deploy (1001)\nUpgrade: shop-api:all (2.4.0, 2.5.0)\nEnd-Date: 2026-11-18  14:02:14\n' > "$out/apt/history.log"
echo "Wrote drill logs to $out"
DRILL

Run it:

Bash
bash ~/outage-drill/make-drill-logs.sh ~/outage-drill/log
cd ~/outage-drill/log
ls -lR

It prints Wrote drill logs to ... and you see syslog, auth.log, auth.log.2.gz, kern.log, dpkg.log, apt/history.log and an nginx folder with access.log, access.log.1, access.log.2.gz and error.log.

The report you are investigating: "the shop returned errors for a few minutes after 14:00 UTC on 18 November". That is all you know.

Check it worked

head -n 3 nginx/access.log prints three requests, the first two stamped [18/Nov/2026:14:00:00 +0000] and the third at 14:00:01.

Step 3 · Measure the outage with awk

In nginx's default combined format, the fields are split by spaces: field 1 is the client address, field 4 starts with the time, field 7 is the path and field 9 is the status code. Count the status codes:

Bash
awk '{ print $9 }' nginx/access.log | sort | uniq -c | sort -rn
Text
    470 200
    320 502
     10 404

sort | uniq -c counts identical lines, which only works when equal lines sit next to each other, hence the first sort. The final sort -rn puts the biggest count first.

320 errors is a number. When did they happen? Group by minute as well:

Bash
awk '{ split($4, t, ":"); print t[2] ":" t[3], $9 }' nginx/access.log | sort | uniq -c

split breaks [18/Nov/2026:14:03:05 at each colon, so t[2] is the hour and t[3] the minute. The output shows normal minutes of 200s, then from 14:03 a column of 502s, and 200s again from 14:07. Find the exact first and last error. The first command stops at the first match with exit, rather than piping into head, so awk is not cut off mid-write:

Bash
awk '$9 == 502 { print; exit }' nginx/access.log
awk '$9 == 502' nginx/access.log | tail -n 1

The first 502 is at 14:03:05 and the last at 14:07:04. You now have the outage window to the second.

For your own server, run the same commands with sudo against /var/log/nginx/access.log, because the file belongs to www-data and the adm group.

Check it worked

You can state the impact in one sentence: about 320 failed requests between 14:03:05 and 14:07:04 UTC.

Step 4 · Check the rotated logs with zgrep

Before calling something an incident, check whether it is normal. Older logs are partly compressed, and zgrep searches .gz files and plain files alike without unpacking them to disk:

Bash
zgrep -c '" 502 ' nginx/access.log*
Text
nginx/access.log:320
nginx/access.log.1:0
nginx/access.log.2.gz:3

The pattern `" 502 ` matches the status straight after the closing quote of the request, so a response size or path that happens to contain 502 is not counted. Three errors two days ago, none yesterday and 320 today: today is not normal background noise.

To read a compressed file, use zcat (or zless), and zcat -f also passes plain files through, so one pipeline covers every rotation:

Bash
zcat -f nginx/access.log* | awk '$9 == 502 { print substr($4, 2, 11) }' | sort | uniq -c

This counts 502s per day across all three files.

Check it worked

The last command prints 3 16/Nov/2026 and 320 18/Nov/2026.

Step 5 · Find out who was affected and who was knocking

If one client caused or suffered all the errors, the cause is likely on its side. If every client got them, look at the server. Rank the addresses that received a 502:

Bash
awk '$9 == 502 { print $1 }' nginx/access.log | sort | uniq -c | sort -rn | head -n 5

192.0.2.77 tops the list with 80, but it also sends a quarter of all traffic (a catalogue sync job, by its user agent), and every other address got roughly 34. Errors spread across all clients point at the server.

Now the SSH noise. Count failed passwords per source address. The address follows the word from, so loop over the fields rather than guessing a fixed position:

Bash
grep 'Failed password' auth.log | awk '{ for (i = 1; i < NF; i++) if ($i == "from") print $(i + 1) }' | sort | uniq -c | sort -rn

One address, 203.0.113.45, failed 60 times between 14:01 and 14:05. Has it been here before, and did it ever get in?

Bash
zgrep -h 'Failed password' auth.log* | grep -c '203.0.113.45'
zgrep -h 'Accepted' auth.log*

The first prints 66: six earlier attempts on 16 November. The second shows only deploy logging in with a key from 198.51.100.200. The attacker never logged in, and failed SSH logins do not stop nginx talking to an app. It is worth blocking (see /tutorials/block-brute-force-logins-with-fail2ban), but it is a separate finding, not the cause.

Recent OpenSSH releases, including the one in Ubuntu 26.04, log authentication as sshd-session rather than sshd; searching for the message text, as here, works with either.

Check it worked

You have two findings with numbers: 502s hit every client, and a password-guessing run from one address got no logins.

Step 6 · Build one timeline across files

Each file stamps time differently: 2026-11-18T14:03:04.512301+00:00 in syslog and auth.log, 2026-11-18 14:02:12 in dpkg.log, 2026/11/18 14:03:05 in nginx's error log. Rewrite them all to one sortable form, add the source, keep only the window and sort. Save this script:

Bash
cat > ~/outage-drill/timeline.sh <<'TIMELINE'
#!/usr/bin/env bash
# Usage: bash timeline.sh LOGDIR FROM TO
# FROM and TO look like 2026-11-18T14:00:00. Prints time, source and message, oldest first.
set -euo pipefail
logs=$1 from=$2 to=$3
{
  for f in syslog auth.log; do
    awk -v src="$f" '{ ts = substr($1, 1, 26); $1 = ""; print ts "\t" src "\t" substr($0, 2) }' "$logs/$f"
  done
  awk '{ ts = $1 "T" $2 ".000000"; $1 = $2 = ""; print ts "\tdpkg.log\t" substr($0, 3) }' "$logs/dpkg.log"
  awk '{ d = $1; gsub("/", "-", d); ts = d "T" $2 ".000000"; $1 = $2 = ""; print ts "\tnginx/error.log\t" substr($0, 3) }' "$logs/nginx/error.log"
} | awk -F'\t' -v from="$from" -v to="$to" '$1 >= from && $1 < to' | sort -s -t "$(printf '\t')" -k1,1
TIMELINE

Each awk prints three tab-separated columns: time, file and message. Setting $1 = "" drops the original stamp. Plain date-time strings in this form sort correctly as text, which is why the window filter can use >= and <. kern.log is left out because syslog already holds the same kernel lines. All files here are in UTC; if yours mix time zones, convert first.

Build the timeline for the ten minutes from 14:00, and see how much each file contributes:

Bash
bash ~/outage-drill/timeline.sh . 2026-11-18T14:00:00 2026-11-18T14:10:00 > ~/outage-drill/timeline.tsv
cut -f2 ~/outage-drill/timeline.tsv | sort | uniq -c

Of nearly 400 lines, 320 are nginx's upstream errors and 60 are failed passwords. They are the loud part. Hide them to see the events:

Bash
grep -vE 'Failed password|connect\(\) failed' ~/outage-drill/timeline.tsv | cut -c1-150

Read it top to bottom:

  • 14:02:09: deploy runs apt install ./shop-api_2.5.0_all.deb with sudo, and dpkg.log shows shop-api upgraded from 2.4.0 to 2.5.0 by 14:02:13.
  • 14:03:04: the kernel's OOM killer kills node (pid 2211, nearly 1.9 GB resident) in shop.service, and systemd records Failed with result 'oom-kill'.
  • 14:03:05: the first 502, one second later. nginx's error log says why: connect() failed (111: Connection refused) while connecting to upstream, meaning nothing was listening on port 3000.
  • 14:07:03: deploy restarts shop.service and the 502s stop at 14:07:04.

The service did not restart itself, so the outage lasted until a person noticed. That is a second thing to fix.

Check it worked

You can write the causal chain in two lines: shop-api 2.5.0 was installed at 14:02, the app ran out of memory and was killed at 14:03:04, nginx returned 502 until a manual restart at 14:07:03. The upgrade is a strong lead for why memory grew, not yet proof: confirm it by watching memory on 2.5.0 or rolling back.

Step 7 · Save the evidence with timestamps

Logs rotate and get deleted, and other people will want to check your conclusion. Copy what you used into one private folder, record when and by whom it was collected, and checksum it so later changes are detectable. Auth logs hold usernames and addresses, so the folder is created readable only by you:

Bash
incident=~/outage-drill/evidence/2026-11-18-shop-502
(umask 077; mkdir -p "$incident/raw")
cp -p syslog auth.log dpkg.log apt/history.log nginx/access.log nginx/error.log "$incident/raw/"
cp ~/outage-drill/timeline.tsv "$incident/"
awk '$4 >= "[18/Nov/2026:14:00:00" && $4 < "[18/Nov/2026:14:10:00"' nginx/access.log > "$incident/access-window.log"

The awk filter compares the timestamps as text, which only works within a single day: month names and the day-first order do not sort as text, so do not reuse it for a window that crosses midnight or a month end. cp -p keeps each file's modification time, which is part of the evidence. Then write the notes, with the collection time taken from the clock rather than typed:

Bash
cat > "$incident/notes.txt" <<NOTES
Incident: 502 errors on shop.example.com
Window examined: 2026-11-18T14:00:00Z to 2026-11-18T14:10:00Z
Collected: $(date -u +%Y-%m-%dT%H:%M:%SZ) by $(id -un) on $(uname -n)

Impact: 320 requests returned 502 from 14:03:05 to 14:07:04 UTC, spread across all clients.
Cause (likely): shop-api upgraded 2.4.0 -> 2.5.0 at 14:02:13; node killed by the OOM killer at 14:03:04;
  nginx could not connect to 127.0.0.1:3000 until a manual restart at 14:07:03.
Separate finding: 66 failed SSH passwords from 203.0.113.45 (60 today, 6 on 16 Nov), no successful login.
Follow-up: check memory use of shop-api 2.5.0 or roll back; add Restart=on-failure to shop.service; block 203.0.113.45.
NOTES
cd "$incident"
find . -type f ! -name SHA256SUMS -print0 | sort -z | xargs -0 sha256sum > SHA256SUMS
sha256sum -c SHA256SUMS
cd ~/outage-drill/evidence
tar -czf 2026-11-18-shop-502.tar.gz 2026-11-18-shop-502
ls -lh 2026-11-18-shop-502.tar.gz

sha256sum -c prints OK for every file. Anyone given the tarball can run the same check.

On your server the source files under /var/log belong to root or adm, so copy them with sudo and then take ownership of the copies:

Bash
sudo cp -p /var/log/syslog /var/log/auth.log /var/log/dpkg.log /var/log/apt/history.log /var/log/nginx/access.log /var/log/nginx/error.log "$incident/raw/"
sudo chown -R "$(id -un):" "$incident"

Real logs can be tens of megabytes. Copying just the window, as with access-window.log, and compressing keeps the download small, which matters when you pull evidence over a prepaid or mobile connection.

Check it worked

sha256sum -c SHA256SUMS inside the case folder prints OK on every line, notes.txt starts with the incident name and a real collection time, and ls -ld on the folder shows drwx------.

When you have finished practising, remove the drill folder:

Bash
cd ~
rm -rf ~/outage-drill

Next steps

  • Ask the journal the same questions by unit and time: /tutorials/search-the-systemd-journal-with-journalctl.
  • Keep enough history to look back a week without filling the disk: /tutorials/manage-log-files-with-logrotate.
  • When the server is slow rather than down: /tutorials/find-why-a-linux-server-is-slow.
  • Check how much memory shop-api 2.5.0 uses before it hits the OOM killer again: /tutorials/find-what-is-using-memory-and-read-oom-killer-messages.

Need this done for you?

Padding does this work for growing companies, from the first diagnosis to a system that keeps working.

Platform Engineering

Get new tutorials

New tutorials, about twice a month.