>_ IzzyLab

Hands-on task

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

API gateway availability in percent

medium~7 min

The gateway writes lines TIME METHOD PATH CODE MS to /var/log/gateway/requests.log. Compute the availability SLI — the share of 2xx responses among all requests, in percent, as an integer rounded down — and write the number (without %) to /root/gateway_sli.txt.

What you'll practise:
  • sli
  • awk
  • percentage
  • code range
  • END block

Topic breakdown

An availability SLI is the share of "good" events among all events: successful responses among all requests. The definition of "good" has to be fixed up front; here it is only 2xx, while redirects and client errors don't count as success. It is convenient to compute in one awk pass: a counter of all lines, a counter of matching ones, and the division in END, when both are known. Division in awk is fractional, so rounding to an integer is done explicitly and at the very end — otherwise you can lose precision too early.

What's checked

  1. share of 2xx computed correctly

What it looks like