>_ IzzyLab

Hands-on task

This task is step 1 of the course “Logs: analysis and housekeeping”

Count server errors

easy~3 min

The shop on this server (nginx, port 80) writes its access log to /var/log/app/access.log, where good requests and errors are mixed together. Open the Site tab above the terminal and browse the shop: the "Place an order" link currently fails with a 500 error, and every request you make lands in the log too. Count how many requests ended with status 500, and write the number (only the number) to /root/count.txt. Count over the whole log, your own requests included.

What you'll practise:
  • grep
  • grep -c
  • regular expressions
  • log parsing
  • field boundaries

Topic breakdown

grep searches for lines matching a pattern, and with the -c flag it returns not the lines themselves but their count. The main subtlety of log parsing is pattern precision: the same digit sequence can appear in different fields of a line (status code, response size, part of a URL), so a naive substring search yields false positives. To catch a value specifically as a standalone field, the pattern must account for its boundaries — for example surrounding spaces or anchors — and extended regular expressions (-E) come in handy for that.

What's checked

  1. the file /root/count.txt is created
  2. the number of 500 errors is counted correctly

What it looks like