Real-time view of Linux network card traffic

Source: Internet
Author: User

Save the following script as an executable script file, for example, called traff.sh.

1, this script can be customized to view the interface, accurate to decimal, and can be flexibly displayed according to the traffic size units.
2. The acquisition interval for this script is 1 seconds.
3, this script does not need to install additional software, can be in emergency situations, such as temporarily want to see if there is a flow through, about how much.
4, some traffic viewing software due to the accuracy of the calculation is different, so the value displayed with this script is not consistent, the display results of this script is compared with Du meter, the difference is very small. There is also the transmission tool itself shows the transmission speed is not accurate.
To use:
1, chmod +x./traff.sh change the file to an executable script.
2,./traff.sh eth0 can start monitoring the interface eth0 traffic, press CTRL + C to exit.

#!/bin/bashwhile ["1"]doeth=$1rxpre=$ (Cat/proc/net/dev | grep $eth | tr: "" | awk ' {print $} ') txpre=$ (Cat/proc/net/dev | grep $eth | tr: "" | awk ' {print $} ') Sleep 1rxnext=$ (Cat/proc/net/dev | grep $eth | tr: "" | awk ' {print $} ') txnext=$ (Cat/proc/net/dev | grep $eth | tr: "" | awk ' {print $} ') Clearecho  -e "\ t RX ' date +%k:%m:%s ' TX" rx=$ ((${rxnext}-${rxpre})) tx=$ ((${txnext}-${txpre} ) if [[$RX-lt 1024x768]];thenrx= "${rx}b/s" elif [[$RX-gt 1048576]];thenrx=$ (echo $RX | awk ' {print $1/1048576 "MB/S"} ') E lserx=$ (echo $RX | awk ' {print $1/1024 "kb/s"} ') fi if [[$TX-lt 1024x768]];thentx= "${tx}b/s" elif [[$TX-gt 1048576]];thent x=$ (echo $TX | awk ' {print $1/1048576 "MB/S"} ') elsetx=$ (echo $TX | awk ' {print $1/1024 "kb/s"} ') fi echo-e "$eth \ t $RX 
    $TX "Done

Real-time view of Linux network card traffic

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.