It has happened to most of us that, all of a sudden we see a spike in bandwidth usage. And, we don’t understand the process which is causing it. So, to monitor bandwidth usage by Process in Ubuntu – we can use Nethogs command-line utility. One of the advantages of tracking Bandwidth usage by process is that – We can identify the process and reason of such bandwidth usage.
So, we can just limit a process and postpone the task if we find it okay to do so. That way, we can efficiently utilize the available bandwidth. How to reduce the bandwidth available to a process is something which we reserve for later (i.e. for subsequent articles). For now, we turn our focus to identify the process first.
We cover NetHogs package installation steps next.
Note: Following operations require superuser privileges. In case you don’t have one then, we advise you to contact your System Administrator for assistance.
Install NetHogs in Ubuntu
NetHogs package is a part of standard Ubuntu repository. So, all we need to do is – update the repository and install the package through following commands. Hence, open a terminal and issue the following –
sudo apt update
And, to install NetHogs –
sudo apt install nethogs
Monitor Bandwidth usage by Process with NetHogs
Following command would run the utility in terminal –
sudo nethogs
The first thing you notice at top left is the version number installed. Just below that, we see four columns at least – PID, USER, PROGRAM and DEV. And, rest columns would be shown depending on the configuration you chose in the beginning. By default it shows – view mode as 0 (0 KB/s). We can change that as shown below –
sudo nethogs -v n
where, value of n can be any of the following –
0 (0 KB/s), the default option
1 (Total KB),
2 (Total B),
3 (Total MB),
4 (MB/s), and
5 (GB/s).
For instance, to get the view mode in Total KB use –
sudo nethogs -v 1
Alternately, if you don’t want to change view modes this way then, press m after you launch NetHogs. And, with every keypress (m) event it would switch modes for us. Apart from that, we can also press s to sort the sent traffic and r to sort receive traffic.
Once you have identified the process which is consuming the bandwidth, note down the its PID (or, Process ID) and take necessary actions on it. As already discussed, we cover that part later.
In conclusion, NetHogs is quite a useful tool to monitor Bandwidth usage by Process. Through NetHogs we can easily manage our network resources.