Monitor Linux Traffic Shell Edition

Source: Internet
Author: User

Want to see the Linux traffic situation in real time, and do not want to go to the third-party tools, you can directly write footsteps run!

System: CentOS 6.5

Principle: Obtain the flow from the/proc/net/dev, and then by the conversion and divided by the interval time to get the flow unit m

#------------------#Author: administrator#created: --Geneva-Ten#------------------#!/bin/bash# Usage Method usage () {Echo "useage: $ ethname intervel"Exit0} #网口配置if[$#-GT1]; ThenEthname=$1Num=`ifconfig|grep${ethname}|WC-l 'if[$num-GT0]; ThenEthname=$1  Else    Echo "Can ' t find $ethname, please Check"Exit1  fifi#时间配置intervel=1if[$#-GT0]; Theninterval=$2Test=`Expr "$interval"\*0`  if["$test"!="0"]; Then         Echo "Invalid <interval> param ' $interval '. It should be a integer number. Usage: $ ethname intervel"Exit-1    fi  if[$interval-lt1]; Then        Echo "Invalid <interval> param ' $interval '. It should be > 0 (seconds). Usage: $ ethname intervel"Exit-1  fifi#函数判断if[$#-ne2 ] ThenusagefiEcho "Starting,device is $1,intervel are $"Echo-E"\ n"typeset Rev Old_reveth=$1Intervel=$2Old_rev=`Cat/proc/net/dev|grep$eth |awk '{print $}'|awk-F:'{print $}'' Old_send=`Cat/proc/net/dev|grep$eth |awk '{print $9}'`#Echo "Old_rev is $old _rev"#Echo "Old_send is $old _send" while true  Do Sleep$intervel Rev=`Cat/proc/net/dev|grep$eth |awk '{print $}'|awk-F:'{print $}'' Send=`Cat/proc/net/dev|grep$eth |awk '{print $9}'`#Echo "Rev is $Rev"#Echo "Send is $Send"diff_1=`awk-V rev= $Rev-v old_rev= $old _rev-v intervel= $intervel'begin{printf "Receive is%6.2f", (rev-old_rev)/1024/1024/intervel * 8}'' Diff_2=`awk-V send= $Send-v old_send= $old _send-v intervel= $intervel'begin{printf "Send is%6.2f", (send-old_send)/1024/1024/intervel * 8}'`  Echo "' date + '%y-%m-%d%h:%m:%s ' speed:in ${diff_1} mbps out ${diff_2} Mbps"Old_rev=$Rev old_send=$Send Done

If you have problems with the use, please contact:

[Email protected]

Monitoring Linux Traffic shell version

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.