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