How to count traffic in a high-speed network under Linux

Source: Internet
Author: User

Resources:

http://www.geekfan.net/5558/http://blog.jobbole.com/23638/http://www.csdn.net/article/2014-03-05/2818640- The Internet-of-things-blog script is based primarily on the SYSFS virtual file system, which is a mechanism used by the kernel to output device or driver-related information to user space. The correlation data of the network interface is output through "/sys/class/net/<ethx>/statistics".

For example, the analysis report on Eth0 's web port is output to these files:

/sys/class/net/eth0/statistics/rx_packets: Packet Data received
/sys/class/net/eth0/statistics/tx_packets: Number of packets transferred
/sys/class/net/eth0/statistics/rx_bytes: Number of bytes Received
/sys/class/net/eth0/statistics/tx_bytes: Number of bytes transferred
/sys/class/net/eth0/statistics/rx_dropped: Packets dropped when packet is received
/sys/class/net/eth0/statistics/tx_dropped: Packets dropped at the time of the contract

netpps.sh---Measuring network ports per second packet#!/bin/bash

Interval= "1" # Update INTERVAL in seconds

If [-Z ']; Then
echo Usage: $ [network-interface]
echo e.g. eth0
Echo shows Packets-per-second
Exit
Fi

While True
Do
r1= ' Cat/sys/class/net/$1/statistics/rx_packets '
t1= ' Cat/sys/class/net/$1/statistics/tx_packets '
Sleep $INTERVAL
R2= ' Cat/sys/class/net/$1/statistics/rx_packets '
T2= ' Cat/sys/class/net/$1/statistics/tx_packets '
txpps= ' Expr $T 2-$T 1 '
rxpps= ' Expr $R 2-$R 1 '
echo "TX $: $TXPPS pkts/s RX $: $RXPPS pkts/s"
Done

netspeed.sh---network bandwidth measurement#!/bin/bash

Interval= "1" # Update INTERVAL in seconds

If [-Z ']; Then
Echo
echo Usage: $ [network-interface]
Echo
echo e.g. eth0
Echo
Exit
Fi

If=$1

While True
Do
r1= ' Cat/sys/class/net/$1/statistics/rx_bytes '
t1= ' Cat/sys/class/net/$1/statistics/tx_bytes '
Sleep $INTERVAL
R2= ' Cat/sys/class/net/$1/statistics/rx_bytes '
T2= ' Cat/sys/class/net/$1/statistics/tx_bytes '
tbps= ' Expr $T 2-$T 1 '
rbps= ' Expr $R 2-$R 1 '
tkbps= ' expr $TBPS/1024 '
rkbps= ' expr $RBPS/1024 '
echo "TX $: $TKBPS kb/s RX $: $RKBPS kb/s"
Done

How to count traffic in a high-speed network under Linux

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.