Linux tool to monitor bandwidth consumption of a specific process (PID)
Solution 1
So since I didn't find any easy/clear/"hit the ground running" solution, I had to made a modest one, fixes, refactoring and more options to come.
-> https://github.com/AymenDaoudi/NeTraf
Solution 2
Have you looked at the tool atop? According to the man page for it:
"Network load is shown per process if the kernel module `netatop' has been installed."
Solution 3
Nethogs might be what you want.
debian/ubuntu/etc
apt-get install nethogs
or rhel/cent/etc
yum install nethogs
You run it on the network interface, e.g.
nethogs eth0
However, its output is bandwidth per process, sent and received. You can also monitor multiple interfaces.
DESCRIPTION NetHogs is a small 'net top' tool. Instead of breaking the traffic down per protocol or per subnet, like most such tools do, it groups band‐ width by process - and does not rely on a special kernel module to be loaded. So if there's suddenly a lot of network traffic, you can fire up NetHogs and immediately see which PID is causing this, and if it's some kind of spinning process, kill it.
UPDATE: OP asked for output to file. You can do it with nethogs:
nethogs -d 1 eth0 > output.txt
-d specifies the time interval in between writes... so you could do the above command and get the desired result.
UPDATE2 OP says TCP and UDP is a requirement. Then attempt to use jnettop. A bit older, but does TCP and UDP. It is available in deb/ubuntu and I think RHEL derivatives. example:
jnettop --display text -t 5 --format CSV
This should be pipe-able to a file.
Related videos on Youtube
AymenDaoudi
Updated on September 18, 2022Comments
-
AymenDaoudi almost 2 years
Is there tool or a command that helps capture the bandwidth consumption of specific process (PID), just like the System Monitor does, but for a single specific process, as shows the following screenshot
I will be happy with a command line tool that at least exports such history to files. (I'm on Ubuntu 16.04)
Update 1
I want at least a tool like Nethogs that can output into files (Nethogs captures only TCP connexions) a similar tool that targets both TCP and UDP would be great
Update 2
Any script, combination of other tools (like wireshark) would help too.
-
AymenDaoudi over 7 yearsI clearly state in the question that Nethogs supports TCP connexions only and I aim to do profiling on an application that uses both TCP and UDP
-
number9 over 7 yearsYou clearly stated "TCP and UDP would be great". Sorry for my mis-interpretation. I will update my response.
-
AymenDaoudi over 7 years@number9 jnettop seems to be interesting, how ever outputing to a file is not continues, is there a way to log the data continuously as long as I'm using my profiled Application, just like the data is displayed continuously on the screen ?
-
SaTa over 3 yearsI could not install netatop on ubuntu 20.04. Do you have any instructions?
-
John Greene over 3 yearsDoes not show PID.