nethogs

Network traffic monitoring tool under the terminal

Supplementary instructions

There are many open source network monitoring tools available for Linux systems. For example, you can use the command iftop to check bandwidth usage. Netstat is used to view interface statistics reports, and top monitors the current running processes of the system. But if you are looking for a tool that can count network bandwidth utilization by process in real time, then NetHogs is worth a look.

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

From the NetHogs project website:

NetHogs is a small net top tool that does not slow down each protocol or each subnet like most tools but groups bandwidth by process. NetHogs does not rely on loading a special kernel module. If a network congestion occurs you can start NetHogs and immediately see which PID is causing the situation. This makes it easy to find out which program is running away and suddenly taking up your bandwidth.

This article introduces you how to install and use NetHogs to monitor network bandwidth usage by process under the Unix/Linux operating system.

grammar

nethogs(options)(parameters)

Options

usage: nethogs [-V] [-h] [-b] [-d seconds] [-v mode] [-c count] [-t] [-p] [-s] [device [device [device .. .]]]
   -V : print version.
   -h : Print this help.
   -b : bughunt mode - implies tracemode.
   -d : Delay update refresh rate in seconds. The default value is 1.
   -v : View mode (0=KB/s, 1=Total KB, 2=Total B, 3=Total MB). The default value is 0.
   -c: number of updates. Default is 0 (no limit).
   -t : tracemode.
   -p : Incite chaos mode (not recommended).
   -s : Sort output by send column.
   -a : Monitor all devices, even loopback/stop.
   device : The device to be monitored. The default is for all interfaces to be up and running, excluding loopbacks

While nethogs is running, press:
   q: exit
   s: Sort by SENT traffic
   r: Sort by RECEIVE traffic
   m: Switch between total (KB, B, MB) and KB/s mode

Other parameters and usage

-d: refresh interval
-h : help
-p : promiscuous mode
-t: trace mode
-V : version

Interactive Commands

Here are some interactive commands (keyboard shortcuts) for NetHogs

Install

Install NetHogs under RHEL, CentOS and Fedora

To install NetHogs, you must enable the EPEL source for your Linux distribution. Then run the following yum command to download and install the NetHogs package.

yum install nethogs

Installing NetHogs under Ubuntu, Linux mint and Debian

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

$ sudo apt-get install nethogs

NetHogs usage

Type the following command to start the NetHogs tool on a RedHat-based system.

nethogs

To execute NetHogs under Debian/Ubuntu/Linux Mint you must have root privileges:

$ sudo nethogs

!nethogs

NetHogs preview under Ubuntu 12.10

As shown in the figure above, the send column and received column display traffic statistics for each process. The total transmit and receive data bandwidth is at the bottom, and the ordering can be controlled using interactive commands, which are discussed below.

NetHogs command line parameters

The following are the parameters of the NetHogs command line. Use -d to add the refresh frequency parameter, and device name is used to detect the bandwidth of a given device or devices (the default is eth0). For example: to set the refresh frequency of 5 seconds, type the following command:

nethogs -d 5
$ sudo nethogs -d 5

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

nethogs eth0
$ sudo nethogs eth0

If you want to monitor the eth0 and eth1 interfaces at the same time, use the following command:

nethogs eth0 eth1
$ sudo nethogs eth0 eth1

For the complete parameter list of the NetHogs command line tool, please refer to the NetHogs manual. To use it, enter man nethogs or sudo man nethogs in the terminal. For more information, please refer to the NetHogs project homepage.