Use iftop to collect network bandwidth usage (#6560)

* Use iftop to collect network bandwidth usage

* fix shellcheck

* more shellchecks

* review comments
This commit is contained in:
Pankaj Garg
2019-10-26 00:06:46 -07:00
committed by Michael Vines
parent be74801236
commit e174af7838
5 changed files with 30 additions and 1 deletions

16
scripts/iftop.sh Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env bash
#
# Reports network bandwidth usage
#
set -e
[[ $(uname) == Linux ]] || exit 0
cd "$(dirname "$0")"
sudo iftop -i "$(ifconfig | grep mtu | grep -iv loopback | grep -i running | awk 'BEGIN { FS = ":" } ; {print $1}')" -nNbBP -t \
| awk '{ if ($3 ~ "=>") { print $2, $7 } else if ($2 ~ "<=") { print $1, $6 }} ' \
| awk 'NR%2{printf "%s ",$0;next;}1' \
| awk '{ print $1, "<=>", $3, ":", $2, $4 }'
exit 1