-
Notifications
You must be signed in to change notification settings - Fork 0
/
pps
executable file
·61 lines (52 loc) · 1.36 KB
/
pps
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
55
56
57
58
59
60
61
#!/bin/sh
set -e
# update interval in seconds
INTERVAL="1"
_usage() {
echo "usage: $0 DEVICE..."
echo " eg: $0 eth0 eth1 ..."
echo "shows packets-per-second"
exit 1
}
[ "$1" ] || _usage
_stat() {
dev=$1
stat=$2
cat "/sys/class/net/$dev/statistics/$stat"
}
title=
for dev in "$@"; do
title=${title:+$title+$dev}
title=${title:-$dev}
done
while true
do
r1=;rd1=;rb1=;t1=;td1=;tb1=
r2=;rd2=;rb2=;t2=;td2=;tb2=
for dev in "$@"; do
r1=$((r1+$(_stat "$dev" "rx_packets")))
rd1=$((rd1+$(_stat "$dev" "rx_dropped")))
rb1=$((rb1+$(_stat "$dev" "rx_bytes")))
t1=$((t1+$(_stat "$dev" "tx_packets")))
td1=$((td1+$(_stat "$dev" "tx_dropped")))
tb1=$((tb1+$(_stat "$dev" "tx_bytes")))
done
sleep "$INTERVAL"
for dev in "$@"; do
r2=$((r2+$(_stat "$dev" "rx_packets")))
rd2=$((rd2+$(_stat "$dev" "rx_dropped")))
rb2=$((rb2+$(_stat "$dev" "rx_bytes")))
t2=$((t2+$(_stat "$dev" "tx_packets")))
td2=$((td2+$(_stat "$dev" "tx_dropped")))
tb2=$((tb2+$(_stat "$dev" "tx_bytes")))
done
tx_pps=$((t2 - t1))
tx_dropped_pps=$((td2 - td1))
tx_bytes=$((tb2 - tb1))
rx_pps=$((r2 - r1))
rx_dropped_pps=$((rd2 - rd1))
rx_bytes=$((rb2 - rb1))
printf "[%s] tx: %9d (dropped: %4d) pkts/s %6d Mb/s rx: %9d (dropped: %4d) pkts/s %6d Mb/s\n" \
"$title" "$tx_pps" "$tx_dropped_pps" "$((tx_bytes*8/1000000))" \
"$rx_pps" "$rx_dropped_pps" "$((rx_bytes*8/1000000))"
done