監控eth1的網卡的流量
# iftop -i eth1
$ iftop -B
$ iftop -n
$ iftop -N
$ iftop -F 192.168.1.0/24 or 192.168.1.0/255.255.255.0
設定檔的位置在~/.iftoprc , 關於設定檔的寫法可以參考 iftop 的 info page.
用途: 用來即時監看網路狀態和各ip所使用的頻寬(很廢話了)
nload默認的是eth0網卡,如果你想監測eth1網卡的流量
#nload eth1
另外,你也可以自己定義流量數值顯示的單位
#nload --help
就可以看到具體的相關參數了。
#!/bin/bash
echo -n "which nic?"
read eth
echo "the nic is "$eth
echo -n "how much seconds:"
read sec
echo "duration is "$sec" seconds, wait please..."
infirst=$(awk '/'$eth'/{print $1 }' /proc/net/dev |sed 's/'$eth'://')
outfirst=$(awk '/'$eth'/{print $10 }' /proc/net/dev)
sumfirst=$(($infirst+$outfirst))
sleep $sec"s"
inend=$(awk '/'$eth'/{print $1 }' /proc/net/dev |sed 's/'$eth'://')
outend=$(awk '/'$eth'/{print $10 }' /proc/net/dev)
sumend=$(($inend+$outend))
sum=$(($sumend-$sumfirst))
echo $sec" seconds total :"$sum"bytes"
aver=$(($sum/$sec))
echo "avrage :"$aver"bytes/sec"