NetHogs: real-time network bandwidth usage statistics by process in Linux

Source: Internet
Author: User
Tags linux mint
There are many open-source network monitoring tools for Linux operating systems on the Internet. For example, you can use the iftop command to check the bandwidth usage, netstat to view the interface statistics report, and the top monitoring system's current processes. However, if you want to find a real-time process-based system

There are many open-source network monitoring tools for Linux operating systems on the Internet. For example, you can use the iftop command to check the bandwidth usage, netstat to view the interface statistics report, and the top monitoring system's current processes. However, if you want to find a tool that can calculate network bandwidth utilization by process in real time, NetHogs is the only tool you need.

NetHogs-network bandwidth monitoring

What is NetHogs?

NetHogs is an open-source command line tool (similar to the top command in Linux) used to count network bandwidth usage in real time by process or program.

From the NetHogs Project website:

NetHogs is a small 'net top' tool. unlike most tools, NetHogs slows down each protocol or the speed of each subnet, but groups bandwidth by process. netHogs does not need to load a special kernel module. if network congestion occurs, you can start NetHogs to immediately see which PID causes this situation. in this way, it is easy to find out which program runs and then suddenly occupies your bandwidth.

This article explains how to install and use NetHogs in Unix/Linux operating systems to monitor network bandwidth usage by process.

Install NetHogs in RHEL, CentOS, and Fedora:

To install NetHogs, you must enable the EPEL source in Linux and then run the following yum command to download and install the NetHogs package.

 
 
  1. # yum install nethogs 

Sample output:

 
 
  1. [root@tecmint~]# yum -y install nethogs 
  2. Loaded plugins:fastest mirror,refresh-packagekit 
  3. Loading mirror speeds from cached hostfile 
  4. *base: mirrors.hns.net.in 
  5. *epel: mirror.nus.edu.sg 
  6. *extras: mirrors.hns.net.in 
  7. *rpmfusion-free-updates: mirrors.ustc.edu.cn 
  8. *rpmfusion-nonfree-updates: mirror.de.leaseweb.net 
  9. *updates: mirrors.hns.net.in 
  10. Setting up Install Process 
  11. Resolving Dependencies 
  12. --> Running transaction check 
  13. ---> Package nethogs.i6860:0.8.0-1.el6 will be installed 
  14. --> Finished Dependency Resolution 
  15. Dependencies Resolved 
  16. =========================================================================================================== 
  17. Package                Arch                Version                    Repository                    Size 
  18. =========================================================================================================== 
  19. Installing: 
  20. nethogs                i686                0.8.0-1.el6                epel                        28k 
  21.   
  22. Transaction Summary 
  23. =========================================================================================================== 
  24. Install       1 Package(s) 
  25. Total download size:28k 
  26. Installed size:50k 
  27. Downloading Packages: 
  28. nethogs-0.8.0-1.el6.i686.rpm                                                        |  28kB     00:00 
  29. Running rpm_check_debug 
  30. Running Transaction Test 
  31. Transaction Test Succeeded 
  32. Running Transaction 
  33.   Installing :nethogs-0.8.0-1.el6.i686                                                          1/1 
  34.   Verifying  :nethogs-0.8.0-1.el6.i686                                                          1/1 
  35. Installed: 
  36.   nethogs.i6860:0.8.0-1.el6 
  37. Complete! 

Install NetHogs in Ubuntu, Linux mint, and Debian:

Run the apt-get command to install the NetHogs package:

 
 
  1. ___FCKpd___2nbsp;sudo apt-get install nethogs 

Sample output

 
 
  1. tecmint@tecmint:~___FCKpd___3nbsp;sudo apt-get install nethogs 
  2. [sudo]password fortecmint: 
  3. Reading package lists...Done 
  4. Building dependency tree 
  5. Reading state information...Done 
  6. The following NEW packages will be installed: 
  7.   nethogs 
  8. 0 upgraded,1 newly installed,0 to remove and 318 not upgraded. 
  9. Need to get 27.1kB of archives. 
  10. After this operation,100kB of additional disk space will be used. 
  11. Get: 1 http://in.archive.ubuntu.com/ubuntu/ quantal/universe nethogs i386 0.8.0-1 [27.1 kB] 
  12. Fetched 27.1kB in 1s (19.8kB/s)  
  13. Selecting previously unselected package nethogs. 
  14. (Reading database... 216058 files and directories currently installed.) 
  15. Unpacking nethogs(from .../nethogs_0.8.0-1_i386.deb)... 
  16. Processing triggers forman-db... 
  17. Setting up nethogs(0.8.0-1)... 

NetHogs usage

Run the following command on the RedHat-based system to start the NetHogs tool. BitsCN.com

 
 
  1. # nethogs 

To execute NetHogs, you must have the root permission, that is, use the sudo command:

 
 
  1. ___FCKpd___5nbsp;sudo nethogs 

Sample preview:

NetHogs preview in CentOS 6.3

NetHogs preview in Ubuntu 12.10

As shown in, the send column and the received column show traffic statistics for each process. The total bandwidth for sending and receiving data is at the bottom, and you can use interactive commands to control sorting. these interactive commands will be discussed below.

NetHogs command line parameters

The following are the parameters of the NetHogs command line. you can use '-d' to add the refresh frequency parameter. the 'device name' is used to detect the bandwidth of a given or certain devices (eth0 by default ). for example, set the refresh frequency for 5 seconds and enter the following command:

 
 
  1. # nethogs -d 5 

Or

 
 
  1. ___FCKpd___7nbsp;sudo nethogs -d 5 

If you only want to monitor the network bandwidth of the device (eth0), run the following command:

 
 
  1. # nethogs eth0 

Or

 
 
  1. ___FCKpd___9nbsp;sudo nethogs eth0 

To monitor the eth0 and eth1 interfaces at the same time, run the following command:

 
 
  1. # nethogs eth0 eth1 

Or

 
 
  1. ___FCKpd___11nbsp;sudo nethogs eth0 eth1 

Other parameters and usage:

 
 
  1. -d: delay for refresh rate. 
  2. -h: display available commands usage. 
  3. -p: sniff in promiscious mode (not recommended). 
  4. -t: trace mode. 
  5. -V: prints Version info.  

NetHogs Interaction Control

The following are some useful interactive controls for NetHogs (keyboard shortcuts:

 
 
  1. -m: Change the units displayed forthe bandwidth inunits like KB/sec->KB->B->MB. 
  2. -r: Sort by magnitude of respectively traffic. 
  3. -s: Sort by magnitude of sent traffic. 
  4. -q: Hit quit tothe shell prompt. 

For the complete parameter list of the NetHogs command line tool, see the NetHogs Manual. you can enter 'Man nethogs 'or 'sudo man nethogs' in the terminal ', for more information, see the NetHogs project homepage.

Related Article

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.