首页 > 系统服务 > 详细

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

时间:2015-09-23 19:35:20      阅读:270      评论:0      收藏:0      [点我收藏+]

查看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

使用效果如下图

技术分享

本文出自 “奋斗的人” 博客,请务必保留此出处http://wodemeng.blog.51cto.com/1384120/1697534

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

原文:http://wodemeng.blog.51cto.com/1384120/1697534

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!