Pete's Linux Advent Calendar 2008
The 18th day
Realtime Graph of ping times
Using gnuplot you can create a realtime graph:
#!/bin/bash
# this function continously prints on stdout the time it takes for the given
# host to answer a ping witha one second interval
sensit() {
local victim="$1"
while true; do
ping -c 1 $victim| awk '/icmp_seq/{print substr($8,6)}'
sleep 1
done
}
# this function prints on stdout the gnuplot commands and
# reads from stdin the data
rotate() {
local victim="$1" xrange="$2" yrange="$3"
echo "set title \"${victim}\""
echo "set ylabel \"time/ms\""
while read line
do
echo "plot $xrange $yrange \"-\" with lines"
lines=`( echo "$lines" ; echo "$line" ) | tail -9`
( echo "$lines"; echo e )
done
}
sensit "$1" | rotate "$1" "[0:10]" "[0:100]" | gnuplot -noraise -selectionTimeout -1