In daily operations, you will encounter a spike in server bandwidth causing site anomalies. As operations personnel, we need to be able to understand the server network card traffic situation, the network card traffic is observed by which programs are occupied.
Today, we introduce a tool for viewing server NIC traffic usage under Linux: Nethogs, an open source tool from GitHub.
It does not rely on modules in the kernel. When our server network is abnormal, you can run the Nethogs program to detect that the program is taking up a lot of bandwidth. Find time saved.
Nethogs Installation:
Method One: The Epel source can be installed directly in Yum
[email protected] src]# Yum install-y libpcap nethogs-y
Method Two: Source code installation
#安装c + + Environment
[email protected] src]# Yum install-y gcc-c++ libpcap-devel.x86_64 libpcap.x86_64 ncurses*
[[email protected] src]# git clone https://github.com/raboof/nethogs
[Email protected] src]# CD nethogs/
[[email protected] src]# make
[[email protected] src]# make install
#完成上面步骤就算安装完成了. If the compilation fails, most of them are missing the compilation environment.
The next step is to test:
Command: "Nethogs NIC Device"
Detect EM1 Network card traffic usage (), run the command
[Email protected] src]# nethogs em1
The first line in the figure is the traffic record of the EM1 network card, indicating that the bandwidth of Em1 NIC is occupied by MySQL program.
In the PID column, you can use the Lsof-p PID to view the process.
or use "Lsof-i: Port number" To see which processes are in use.
such as view MySQL port lsof-i:3306
View server NIC traffic through Nethogs