有时就算你有网卡监控的工作如cacti nagios这些长时间的监控工具,但有时为了解决临时的瞬时的一些检测任务,就需要直接查看到网卡的流量,还可以变化成自己喜欢的格式,只要你愿意去改脚本。这个脚本的单位跟cacti展示的是一样的。
#!/bin/bash # ------------------------------------------------------------------------------- # Filename: netflood.sh # Revision: 1.2 # Date: 2007/08/30 # Author: Ajian # Email: ajian521#gmail.com # Website: www.ohlinux.com # Description: LAN traffic monitor # ------------------------------------------------------------------------------- # Copyright: 2009 (c) Ajian # License: GPL # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # ------------------------------------------------------------------------------- #Version 1.1 2007/08/30 #create the script #Version 1.2 2008/01/10 #modify the script and add the variable. NIC=eth1 while : ; do time=`date +%m"-"%d" "%k":"%M` day=`date +%m"-"%d` rx_before=`ifconfig $NIC|sed -n "8"p|awk '{print $2}'|cut -c7-` tx_before=`ifconfig $NIC|sed -n "8"p|awk '{print $6}'|cut -c7-` sleep 2 rx_after=`ifconfig $NIC|sed -n "8"p|awk '{print $2}'|cut -c7-` tx_after=`ifconfig $NIC|sed -n "8"p|awk '{print $6}'|cut -c7-` rx_result=$[(rx_after-rx_before)/256] tx_result=$[(tx_after-tx_before)/256] echo "$time Now_In_Speed: "$rx_result"kbps Now_OUt_Speed: "$tx_result"kbps" sleep 2 done