2016-05-24

Mikael Lövqvist

Plotting pretty ping times

by Mikael Lövqvist on

The other day my ISP wanted me to plot ping times using some software that would only run on Windows 7 and up which means it will not work in the current version of Wine. I decided to use gnuplot instead.

First I had to extract the ping times from the ping command

This script reads stdin, finds the time=NN ms and outputs the UNIX epoch time followed by the ping time on each line.

I used the following command
$ ping ping.sunet.se -i 5 | python ~/timestamp_ping.py | tee ~/sunet_ping_ts.log

ping will ping ping.sunet.se in intervals of 5 seconds
python (python3 on my system) is called to extract the ping times as they come in. The sys.stdout.flush command is used so that each line will be outputted as it is processed.
tee is saving the output to the log-file and also displaying the lines as they are processed.

After a few hours I had a nice data set of a few thousand ping times that I could plot using this gnuplot script

Note on line 22 I add 2*3600 to the time to adjust it to my local timezone. There might be a better way to do this but this was the quickest solution I could find for now.

And here is the result:

Plot of ping times

Useful links:

ping manpage, http://linux.die.net/man/8/ping
tee manpage, http://linux.die.net/man/1/tee
gnuplot demos, http://www.gnuplot.info/screenshots/index.html#demos
python3 documentation, https://docs.python.org/3/