summaryrefslogtreecommitdiffstats
path: root/analyze.sh
blob: 33799cc1e9bfe2d6ec06cbc02f14d767462354c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash

sleep=1

int=$(ip addr show | grep "192\.168\.2\." | awk '{ print $NF }')

stats1=($(ethtool -S $int | grep  -P "rx\d?_(packets|bytes)" | awk '{ print $2 }'))
sleep $sleep
stats2=($(ethtool -S $int | grep  -P "rx\d?_(packets|bytes)" | awk '{ print $2 }'))

for i in "${!stats1[@]}"; do
    diff=$(bc <<< "(${stats2[$i]} - ${stats1[$i]}) / $sleep")

    if [ $((i & 1)) -eq 0 ]; then
	if [ $i -lt 2 ]; then
	    echo -n "Total:"
	elif [ $i -lt 4 ]; then
	    echo -n "Phi  :"
	else
	    echo -n "Queue:"
	fi
	printf "packets: %9.3f kpps" $(bc -l <<< "1 * $diff / 1000")
    else
	printf ", bandwidth: %9.3f Gb/s\n" $(bc -l <<< "8. * $diff / 1024 / 1024 / 1024")
    fi

#echo $i
done