Graphing bandwidth of a pcap file on arbitrary granularity

OK it seems like i’ve done this enough times in my career w/ 1-off command line, i thought i would share w/ the group. This may not have the mass-market appeal of the cat videos, but its probably better for productivity.

The below script will take a capture file, and then graph it’s bandwidth on any arbitrary time-grid granularity. E.g. if you want to know the bandwidth of something over any 0.1s interval, 1s interval, etc.

#!/bin/sh
set -e
if [ $# != 2 ]
then
 echo "Usage: $0 cap-file granularity(s)"
 exit 1
fi
ifile="$1"
gran="$2"
d=$(mktemp -d)
tshark -o column.format:'"T","%t","L","%L"' -r "$ifile" | awk -v gran=$gran '
BEGIN {
 offset = 0
 printf("Time,Delta-Bytes,Bps\n");
}
{
 if ( ($1 - offset) > gran) {
 b=bytes[offset]
 offset += gran
 bytes[offset] = 0
 printf("%f,%u,%6.2f\n", offset, b, (8.0 * b) / gran)
 }
 bytes[offset] += $2
}
' > $d/x.dat
cat << EOF > $d/gnuplot.txt
set datafile separator ","
set title "$ifile bitrate (${gran}s granularity)"
set xlabel "Time(seconds)"
set ylabel "Bitrate(bps)"
plot "$d/x.dat" using 1:3 title "$ifile" with lines
pause -1
EOF
echo "Press return to finish"
gnuplot $d/gnuplot.txt
rm -rf $d

 


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *