In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, I will talk to you about how the Linux system counts the traffic in the high-speed network. Many people may not know much about it. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.
Although there are many traffic monitoring tools in the Linux system, the system overhead of packet interception in the user space is so high that the traffic monitoring tools can not handle high-speed (above Gb) network interfaces.
Scripts are mainly based 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 relevant analysis data of the network interface will be output through "/ sys/class/net//statistics".
For example, eth0's network port analysis report is 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 that drops when a packet is received
/ sys/class/net/eth0/statistics/tx_dropped: the amount of data dropped by the transport packet
This data is automatically refreshed when the kernel data changes. Therefore, you can write a series of scripts to analyze and calculate traffic statistics. Here's the script (thanks to joemiller). The first script is to count the amount of data per second, including receiving (RX) or sending (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.
Measure the packet per second of the network port:
#! / bin/bash
INTERVAL= "1" # update interval in seconds
If [- z "$1"]; then
Echo
Echo usage: $0 [network-interface]
Echo
Echo e.g. $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
Powered by Ad.Plus
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 TXPPS pkts/s RX RXPPS pkts/s"
Done
Network bandwidth measurement
#! / bin/bash
INTERVAL= "1" # update interval in seconds
If [- z "$1"]; then
Echo
Echo usage: $0 [network-interface]
Echo
Echo e.g. $0 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 $T2-$T1
RBPS=expr $R2-$R1
TKBPS=expr $TBPS / 1024
RKBPS=expr $RBPS / 1024
Echo "TX TKBPS kb/s RX RKBPS kb/s"
Done
The screenshot below shows the output of the two scripts above.
What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.
After reading the above, do you have any further understanding of how the Linux system counts the traffic in high-speed networks? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.