(1) Network card Monitoring script
#!/bin/bash
Echo-n "Please enter the interface (ETH0) for the NIC you want to query:"
Read ETH
echo "The NIC interface you want to query is" $eth
Declare-i sec
Echo-n "Enter the time to wait (in seconds):"
Read sec
echo "You want to see a single (b,k,m) of traffic:"
Read type
If ["$sec" = "0"]
Then
Sec=1
Fi
echo "You calculate the average flow in the $sec seconds"
infirst=$ (awk '/' $eth '/{print $ '/proc/net/dev |sed ' s/' $eth '://')
outfirst=$ (awk '/' $eth '/{print $ A} '/proc/net/dev)
sumfirst=$ (($infirst + $outfirst))
Sleep $sec "s"
inend=$ (awk '/' $eth '/{print $ '/proc/net/dev |sed ' s/' $eth '://')
outend=$ (awk '/' $eth '/{print $ A} '/proc/net/dev)
sumend=$ (($inend + $outend))
sum=$ (($sumend-$sumfirst))
aver=$ (($sum/$sec))
ksum=$ (($sum/1024/8))
msum=$ (($sum/1024/1024/8))
kaver=$ (($ksum/$sec))
maver=$ (($msum/$sec))
Case $type in
m| M) echo $sec "The total flow in seconds is:" $msum "MB"
echo "Average flow:" $maver "mb/sec";;
k| K) echo $sec "The total flow in seconds is:" $ksum "KB"
echo "Average flow:" $kaver "kb/sec";;
*) echo $sec "The total flow in seconds is:" $sum "bytes"
echo "Average flow:" $aver "bytes/sec";;
Esac
(2) scripts (common)
#!/bin/bash
While ["1"]
Do
Eth=$1
rxpre=$ (Cat/proc/net/dev | grep $eth | tr: "" | awk ' {print $} ')
txpre=$ (Cat/proc/net/dev | grep $eth | tr: "" | awk ' {print $} ')
Sleep 1
rxnext=$ (Cat/proc/net/dev | grep $eth | tr: "" | awk ' {print $} ')
txnext=$ (Cat/proc/net/dev | grep $eth | tr: "" | awk ' {print $} ')
Clear
Echo-e "\ t RX ' date +%k:%m:%s ' TX"
rx=$ ((${rxnext}-${rxpre}))
tx=$ ((${txnext}-${txpre}))
if [[$RX-lt 1024x768]];then
rx= "${RX}B/S"
elif [[$RX-gt 1048576]];then
rx=$ (echo $RX | awk ' {print $1/1048576 "MB/S"} ')
Else
rx=$ (echo $RX | awk ' {print $1/1024 ' kb/s "} ')
Fi
if [[$TX-lt 1024x768]];then
tx= "${TX}B/S"
elif [[$TX-gt 1048576]];then
tx=$ (echo $TX | awk ' {print $1/1048576 "MB/S"} ')
Else
tx=$ (echo $TX | awk ' {print $1/1024 ' kb/s "} ')
Fi
Echo-e "$eth \ t $RX $TX"
Done
(4) Here is the usage
Test speed
/usr/local/nagios/libexec/check_traffic.sh-v 2c-c public-h 127.0.0.1-i 2-w 1200,1500-c 1700,1800-k-B
/usr/local/nagios/libexec/check_traffic.sh-v 2c-c public-h 127.0.0.1-i 2-w 300,350-c 500,600-k-B
Check_command check_traffic!1-w 600,600-c 800,800
Netstat-n | awk '/^tcp/{++s[$NF]}end{for (A in S) print A,s[a]} '
Network card structure of the FTP
Interface index 1 orresponding to Lo
Interface index 2 orresponding to EM1
Interface index 3 orresponding to EM2
Interface Index 4 orresponding to EM3
Interface index 5 orresponding to EM4
SNMP View live fill traffic (15 seconds of data)
Snmpdelta-c public-v 1-cs localhost if-mib::ifinucastpkts.3 if-mib::ifoutucastpkts.3
Server network card monitoring using