octo / liboping

Protocol independent ANSI-C ping library and command line utility.
http://noping.cc/
GNU Lesser General Public License v2.1
184 stars 57 forks source link

Please add option to output running statistics #53

Open akorn opened 4 years ago

akorn commented 4 years ago

oping(8) currently outputs one line per packet, like ping(1), and summary statistics on exit.

It would be useful to have an output mode where it prints statistics concerning the last n packets, or the last t seconds; something like this:

TARGET: last n: x packets transmitted, x received, xx.xx% packet loss, RTT[ms]: min = xx, median = xx, p(95) = xx, max = xx

The output should be line-oriented and parseable.

Use case: I have a script that monitors which of my uplinks is usable. Currently I invoke oping periodically, but it takes a while each time to get statistically significant results on e.g. packet loss. If I could instead keep oping running and read its output from a pipe, I would always have up to date statistics.

akorn commented 4 years ago

Actually, a sliding average over several different numbers of packets would also be useful (like the system load average). Say, if the average loss over the last 1000 packets is 3%, I might still think the link is good; but if the average loss over the last 25 packets it 30%, it's just going bad.

So I'd use the longer-term average to mark the link as "good" but the short-term average to mark it as "bad".

octo commented 4 years ago

I'd argue that there are two feature requests in this:

  1. Add running statistics to the oping output. (noping already has that)
  2. Provide an option to limit statistics to the last n packets (currently considers all packets since start).

Both seem reasonable and I would be happy to merge such pull requests.

Since load average came up: load average uses exponential decay, not a sliding window. While exponential decay is much easier to implement, I'd argue that a sliding window is more correct and much easier to grasp. For example, if you looked at the last 100 packets and the hosts goes from 0% packet loss to 100% packet loss, you'd expect the packet loss average to go from 0% to 100% in one percent point steps. With exponential decay, that is not the case.