linux网卡O I流量查询,查看linux server网络I/0流量的shell脚本

查看linux server网络流量的shell脚本

上传下载大量文件的时候,可以使用这个脚本来实现监控!#!/bin/sh

###统计5s内的平均流量,以Mb为单位

if [ "$1" = "" ];then

echo -e "\n      use interface_name after the script,like \"$0 eth0\"...\n"

exit -1

fi

echo -e "\n      start monitoring the $1,press \"ctrl+c\" to stop"

echo ----------------------------------------------------------

#ls  /etc/sysconfig/network-scripts/|grep ifcfg|cut -d "-" -f 2

while true

do

RX_bytes=`cat /proc/net/dev|grep "$1"|awk '{print $1}'|cut -d ":" -f 2`

TX_bytes=`cat /proc/net/dev|grep "$1"|awk '{print $9}'`

sleep 5

RX_bytes_later=`cat /proc/net/dev|grep "$1"|awk '{print $1}'|cut -d ":" -f 2`

TX_bytes_later=`cat /proc/net/dev|grep "$1"|awk '{print $9}'`

###Mb=B*8/1024/1024

speed_RX=`echo "scale=2;($RX_bytes_later - $RX_bytes)*8/1024/1024/10"|bc`

speed_TX=`echo "scale=2;($TX_bytes_later - $TX_bytes)*8/1024/1024/10"|bc`

printf "%-3s %-3.1f %-10s %-4s %-3.1f %-4s\n" IN: $speed_RX Mb/s OUT: $speed_TX Mb/s

done

使用效果如下图

88c6ba4ad3d4365932a6d4169f0366f2.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值