Step 7 of 9 · lab · 30 min
A report from the nginx log
The five longest requests and the bytes per response code for one day, from an nginx log cut in two by rotation.
Situation
Your manager wants a report on the shop.lab.test store site for yesterday, 19 October:
which requests the site took longest to handle, and how many bytes it sent with each response
code. The site runs on nginx; its request log is /var/log/nginx/shop.access.log, and the
line format is set in /etc/nginx/conf.d/shop-log.conf.
The manager compares reports from different days, so the report always has the same layout.
Task
Build ~/report.txt out of two sections:
[slowest]
<time> <URL>
…
[bytes]
<code> <bytes>
…
- The
[slowest]section holds the five longest requests of 19 October: the request time as written in the log and the request URL, separated by a space. The longest one first. - The
[bytes]section holds every response code that occurs on 19 October and the sum of bytes sent with that code during the day ($body_bytes_sent), separated by a space. Codes in ascending order.
The day runs from 00:00:00 to 23:59:59 by the log's clock. Only read the logs, don't change
them. First look at what you are working with: ls -l /var/log/nginx and head -n 3 of the
log. Build each section as a pipeline one link at a time and watch the output on screen; send
it to the file once the output is right.
Lab · on your own
No commands are given in this lab: type them in the terminal yourself. Goals are checked on the machine after every command.
Goals
0 of 2-
The [slowest] section lists the five longest requests of 19 October — time and URL, the longest first — not done yet
-
The [bytes] section holds the sum of bytes of 19 October for each response code, codes in ascending order — not done yet
The machine is starting
Hints
0 of 3Lab goals
0 of 2-
The [slowest] section lists the five longest requests of 19 October — time and URL, the longest first — not done yet
-
The [bytes] section holds the sum of bytes of 19 October for each response code, codes in ascending order — not done yet
Goals are checked on the machine after every command.