In Linux system operation, tools can be used to monitor network traffic, but there are certain limitations on the monitoring of high-speed networks. For high-speed network traffic monitoring, shell scripts can be used. The following small series will introduce you to Linux. A script that monitors high-speed network traffic.
In this article we describe a simple Shell script that can monitor network traffic and does not rely on slow libpcap library. These scripts support high-speed network interfaces of the size above Gb. If you are interested in the network traffic of "aggregation type", they can count the traffic on each network interface.
Scripts are primarily based on the sysfs virtual file system, a mechanism used by the kernel to output device or driver related information to user space. The relevant analysis data of the network interface will be output through “/sys/class/net/"ethX"/statistics”.
For example, the analysis report on the eth0 network port will be output to these files:
/sys/class/net/eth0/statistics/rx_packets: Received packet data
/sys/class/net/eth0/statistics/tx_packets: Number of packets transmitted
/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: The amount of data dropped when a packet is received < Br>
/sys/class/net/eth0/statistics/tx_dropped: The amount of data dropped by the transport packet
These data are automatically refreshed when the kernel data changes. Therefore, you can write a series of scripts to analyze and calculate traffic statistics. Here is the script like this (thanks to joemiller). The first script is to count the amount of data per second, including receive (RX) or send (TX). The latter is a description of the receive (RX) transmit (TX) bandwidth in network transmission. No tools are required for installation in these scripts.
Measuring network port data per second:
#! /bin/bash
INTERVAL=“1” # update interval in seconds
if [ -z “$1” ]; then
echo
echo usage: $0 [network-interface]
echo
echo eg $0 eth0
echo
echo shows packets-per-second
exit
fi
IF=$1
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 $T2 - $T1`
RXPPS=`expr $R2 - $R1`
echo “TX $1: $TXPPS pkts/s RX $1: $RXPPS pkts/s”
done
Previous12Next Total 2 Pages
VirtualBox is a very useful virtual machine software, so it has been sought after b
I accidentally deleted Ubuntus Grub boot under UEFI, so I cant boot into Ubuntu aut
Linux input method switching is the same as Windows, you can also use shortcut swit
I have been installing LibreOffice on Linux for a while. I need to uninstall LibreOffice for various
Linux system Vim how to install YouCompleteMe plug-in
Ubuntu steps to install VLC player
Method for monitoring Linux command completion using PV commands
How to create symbolic links for Linux systems
How to delete the specified file in swap
How does Ubuntu automatically switch between the mouse and the shared clipboard under VirtualBox?
Linux system NBMA and BMA exchange method introduction
Linux changes the capacity of VirtualBox disk
Linux changes the way Docker runs the root directory
How to clean up Git and Repo invalid code in Linux system
Linux/Ubuntu 11.10 How to build Android4.0.3 development environment
Linux df command using instance summary
System comes with components to quickly solve network congestion problems
Win8 system running program shows "return a reference from the server"
XP bypasses the two methods of disk self-test
Win10 update KB3116869 patch error 0x80004005 solution
Alipay send express function using tutorial
KB3035583 patch installed but no solution for Win10 booking icon
How Win8 uses the board application
LOL box skin can not be used? LOL box skin off the line solution!
Set the widget in the hummingbird computer acceleration to self-starting