甘南村希望小学的图片:监控网卡流量脚本

来源:百度文库 编辑:偶看新闻 时间:2024/05/03 09:30:18
监控网卡流量脚本
前言:这个脚本是用来监控网卡的瞬时流量的,跟Cacti的计算结果完全吻合。如果想让系统每多少分钟取一次可以将此脚本改良成任务计划执行的脚本并记录到日志中。

    文章来源: http://makert.blog.51cto.com/209063/49396  #!/bin/bash
############################
##
##  Author : Ajian
##  Time : 2007-9-21
##  File:  netflood.sh
##  watch the eth0 or eth1
#################################
#Set the varible.
ETH=eth0
while : ; do
        time=`date +%m"-"%d" "%k":"%M`
        day=`date +%m"-"%d`
        rx_before=`ifconfig $ETH|sed -n "8"p|awk '{print $2}'|cut -c7-`
        tx_before=`ifconfig $ETH|sed -n "8"p|awk '{print $6}'|cut -c7-`
        sleep 2
        rx_after=`ifconfig $ETH|sed -n "8"p|awk '{print $2}'|cut -c7-`
        tx_after=`ifconfig $ETH|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