码迷,mamicode.com
首页 > 其他好文 > 详细

网卡流量监控脚本

时间:2015-11-20 21:31:33      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:

#!/bin/bash
while [ "1" ]
do
eth=$1
RXpre=$(cat /proc/net/dev | grep $eth | tr : " " | awk {print $2})
TXpre=$(cat /proc/net/dev | grep $eth | tr : " " | awk {print $10})
sleep 1
RXnext=$(cat /proc/net/dev | grep $eth | tr : " " | awk {print $2})
TXnext=$(cat /proc/net/dev | grep $eth | tr : " " | awk {print $10})
#clear
echo  -e  "\t RX `date +%k:%M:%S` TX"
RX=$((${RXnext}-${RXpre}))
TX=$((${TXnext}-${TXpre}))
 
if [[ $RX -lt 1024 ]];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 1024 ]];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

 使用方法如下,RX为入流量,TX为出流量

# ./ttt.sh eth1
RX 19:33:09 TX
eth1 35.6152KB/s 5.69769MB/s
RX 19:33:10 TX
eth1 40.1328KB/s 6.60828MB/s
RX 19:33:11 TX
eth1 2.53724MB/s 8.39092MB/s
RX 19:33:12 TX
eth1 168.514KB/s 5.5667MB/s
RX 19:33:13 TX
eth1 4.6224MB/s 7.22006MB/s
RX 19:33:14 TX
eth1 240.126KB/s 6.34822MB/s
RX 19:33:15 TX
eth1 3.37922MB/s 7.15415MB/s
RX 19:33:16 TX
eth1 1.54262MB/s 6.35194MB/s
RX 19:33:17 TX
eth1 39.1971MB/s 2.31175MB/s

网卡流量监控脚本

标签:

原文地址:http://www.cnblogs.com/wedata/p/4982159.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!