Created
November 30, 2012 05:59
-
-
Save caok/4174006 to your computer and use it in GitHub Desktop.
通过shell 脚本查看服务器的时时流量
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ETH=$1 | |
ETH=${ETH:-eth0} | |
IP=`ifconfig $ETH|awk -F '[ :]+' '/inet addr/{print $4}'` | |
while true;do | |
let I+=1 | |
NOW=`date +"%F %T"` | |
TX1=`ifconfig $ETH|grep bytes|awk -F '[ :]+' '{print $9}'` | |
RX1=`ifconfig $ETH|grep bytes|awk -F '[ :]+' '{print $4}'` | |
sleep 1 | |
TX2=`ifconfig $ETH|grep bytes|awk -F '[ :]+' '{print $9}'` | |
RX2=`ifconfig $ETH|grep bytes|awk -F '[ :]+' '{print $4}'` | |
let TX=(TX2-TX1)/1024 | |
let RX=(RX2-RX1)/1024 | |
let TX_TOTAL+=$TX | |
let RX_TOTAL+=$RX | |
let TX_AVERAGE=TX_TOTAL/${I} | |
let RX_AVERAGE=RX_TOTAL/${I} | |
clear | |
printf "%10s\t%20s\n" "Device $ETH [$IP]" "$NOW" | |
echo "=============================================================" | |
printf "%10s\t%20s\t%20s\n" CURRENT: in:${RX}KB/s out:${TX}KB/s | |
printf "%10s\t%20s\t%20s\n" AVERAGE: in:${RX_AVERAGE}KB/s out:${TX_AVERAGE}KB/s | |
printf "%10s\t%20s\t%20s\n" TOTAL: in:${RX_TOTAL}KB out:${TX_TOTAL}KB | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment