summaryrefslogtreecommitdiffstats
path: root/analyze3.sh
blob: 256a4c573daeac231d4a58c1cb7058a1dc86dbd1 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#! /bin/bash

sleep=1

#Doesn't work with LibVMA.
#iptables -D INPUT -p udp --match multiport --dports 4000:4100 -j traf &> /dev/null
#iptables -X traf &> /dev/null
#iptables -N traf 
#iptables -A INPUT -p udp --match multiport --dports 4000:4100 -j traf
#iptables -Z traf
#iptables -L traf -v -n -x 

function stat {
    ints=$1

    for i in "${!ints[@]}"; do
	int="${ints[$i]}"
	stats1[$i]=$(ethtool -S $int | grep  -P "rx_(packets|bytes)_phy" | awk '{ print $2 }')
    done
    sleep $sleep
    for i in "${!ints[@]}"; do
	int="${ints[$i]}"
	stats2[$i]=$(ethtool -S $int | grep  -P "rx_(packets|bytes)_phy" | awk '{ print $2 }')
    done

    pksum=0
    bwsum=0
    for i in "${!stats1[@]}"; do
	stat1=(${stats1[$i]})
	stat2=(${stats2[$i]})
	
	pk1=${stat1[0]}
	pk2=${stat2[0]}

	bw1=${stat1[1]}
	bw2=${stat2[1]}

	pkdiff=$(bc <<< "($pk2 - $pk1) / $sleep")
        bwdiff=$(bc <<< "($bw2 - $bw1) / $sleep")
	
	printf "%10s" "${ints[$i]}"
	printf "  packets: %9.3f kpps" $(bc -l <<< "1. * $pkdiff / 1000")
	printf ", bandwidth: %9.3f Gb/s\n" $(bc -l <<< "8. * $bwdiff / 1024 / 1024 / 1024")

	pksum=$(($pksum + $pkdiff))
	bwsum=$(($bwsum + $bwdiff))
    done
    printf "%10s" "Total"
    printf "  packets: %9.3f kpps" $(bc -l <<< "1. * $pksum / 1000")
    printf ", bandwidth: %9.3f Gb/s\n" $(bc -l <<< "8. * $bwsum / 1024 / 1024 / 1024")
}

ints=(ens1 ens11 ens1d1 ens11d1)
stat $ints