Categories
DailyOps

How to display current bandwidth grouped by a process

Use nethogs utility to display current bandwidth grouped by a process

Inspect nethogs package description.

$ sudo apt info nethogs
Package: nethogs
Version: 0.8.5-2+b1
Priority: optional
Section: net
Source: nethogs (0.8.5-2)
Maintainer: Paulo Roberto Alves de Oliveira (aka kretcheu) 
Installed-Size: 80.9 kB
Depends: libc6 (>= 2.15), libgcc1 (>= 1:3.0), libncurses6 (>= 6), libpcap0.8 (>= 0.9.8), libstdc++6 (>= 5.2), libtinfo6 (>= 6)
Homepage: https://github.com/raboof/nethogs
Tag: admin::monitoring, implemented-in::c++, role::program,
 uitoolkit::ncurses, use::monitor, works-with::network-traffic
Download-Size: 30.9 kB
APT-Sources: http://deb.debian.org/debian bullseye/main amd64 Packages
Description: Net top tool grouping bandwidth per process
 NetHogs is a small 'net top' tool. Instead of breaking the traffic down per
 protocol or per subnet, like most tools do, it groups bandwidth by process.
 NetHogs does not rely on a special kernel module to be loaded.

Install nethogs package.

$ sudo apt install nethogs

By default, it requires root privileges.

$ /usr/sbin/nethogs 
To run nethogs without being root you need to enable capabilities on the program (cap_net_admin, cap_net_raw), see the documentation for details.

Enable capabilities required to use it a regular user.

$ sudo setcap "cap_net_admin,cap_net_raw+pe" /usr/sbin/nethogs

Create a link for convenience.

$ sudo ln -s /usr/sbin/nethogs /usr/local/bin/

Display help information.

$ nethogs -h
usage: nethogs [-V] [-h] [-b] [-d seconds] [-v mode] [-c count] [-t] [-p] [-s] [device [device [device ...]]]
                -V : prints version.
                -h : prints this help.
                -b : bughunt mode - implies tracemode.
                -d : delay for update refresh rate in seconds. default is 1.
                -v : view mode (0 = KB/s, 1 = total KB, 2 = total B, 3 = total MB). default is 0.
                -c : number of updates. default is 0 (unlimited).
                -t : tracemode.
                -p : sniff in promiscious mode (not recommended).
                -s : sort output by sent column.
   -a : monitor all devices, even loopback/stopped ones.
                device : device(s) to monitor. default is all interfaces up and running excluding loopback

When nethogs is running, press:
 q: quit
 s: sort by SENT traffic
 r: sort by RECEIVE traffic
 m: switch between total (KB, B, MB) and KB/s mode

Execute nethogs to monitor bandwitch usage.

$ nethogs