• Linux 监控每秒网卡流量


    #! /bin/bash 
    . ~/.bash_profile
    #Author: Vogts WangTao 2008-12-18 
    #Get summry info 
    host2=` /sbin/ifconfig eth0 | grep inet | awk -F ':' '{print $2}' | awk '{print $1}'`
    echo "Current Ip: "`/sbin/ifconfig eth0 | grep inet` 
    echo "Summry info: "`/sbin/ifconfig eth0 | grep bytes` 
    #sleep 1 second ,monitor eth0 
    receive1=`cat /proc/net/dev|grep eth0 | awk '{print $1}'|sed -s 's/eth0://g'` 
    receive_pack1=`cat /proc/net/dev|grep eth0 | awk '{print $2}'` 
    send1=`cat /proc/net/dev|grep eth0 | awk '{print $9}'` 
    send_pack1=`cat /proc/net/dev|grep eth0 | awk '{print $10}'` 
    sleep 1 
    receive2=`cat /proc/net/dev|grep eth0 | awk '{print $1}'|sed -s 's/eth0://g'` 
    receive_pack2=`cat /proc/net/dev|grep eth0 | awk '{print $2}'` 
    
    receive_cnt=`expr $receive2 - $receive1` 
    receive_pack_cnt=`expr $receive_pack2 - $receive_pack1` 
    
    send2=`cat /proc/net/dev|grep eth0 | awk '{print $9}'` 
    send_pack2=`cat /proc/net/dev|grep eth0 | awk '{print $10}'` 
    
    send_cnt=`expr $send2 - $send1` 
    send_pack_cnt=`expr $send_pack2 - $send_pack1` 
    
    num1=`expr  $receive_cnt / 1024`
    num2=`expr  $receive_pack_cnt / 1024`
    num3=`expr  $send_cnt / 1024`
    num4=`expr  $send_pack_cnt / 1024`
    echo 'eth0 Receive KBytes:' $num1 ' Packets:' $num2
    echo 'eth0 Send KBytes:' $num3 ' Packets:' $num4
    if [ "$num1" -gt 200 ]
       then
       smail.pl "$host2-eth0 receive_cnt is ${num1}kb"
    fi
    
    if [ "$num3" -gt 200 ]
       then
       smail.pl "$host2-eth0 send_cnt is ${num3}kb"
    fi

  • 相关阅读:
    ubuntu18 升级cmake
    开源镜像站汇总
    ubuntu18安装go
    tendermint框架及Tx执行流程
    常用python内置函数
    根据列号返回列名
    Valid Number
    Remove Duplicates from Sorted List II
    vector排序问题<unresolved overloaded function type>
    Spiral Matrix
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351582.html
Copyright © 2020-2023  润新知