>_ IzzyLab

Hands-on task

This task is step 12 of the course “Monitoring and metrics”

Median response time

medium~5 min

In /root/times.txt there's one number per line — the response time in ms. Find the median (the number of values is odd — it's the middle element of the sorted values) and write it to /root/median.txt.

What you'll practise:
  • median
  • sort -n
  • awk
  • percentiles
  • numeric sort

Topic breakdown

The median is the value right in the middle of the values sorted in ascending order; unlike the mean, it's robust to outliers. For an odd number of values N it's the element at index (N+1)/2 after sorting, and you must sort numerically (sort -n), not lexicographically, otherwise 10 ends up before 2. From there you just pick the element at the right position — whether with an array in awk or with a line-selection pipeline.

What's checked

  1. median is correct

What it looks like