Linux tool to monitor bandwidth consumption of a specific process (PID)

9,651

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.

Share:
9,651

Related videos on Youtube

AymenDaoudi
Author by

AymenDaoudi

Updated on September 18, 2022

Comments

  • AymenDaoudi
    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 enter image description here

    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.

    • Elliott Frisch
      Elliott Frisch over 7 years
      tcpdump (and pcap), or a higher level tool like ntop.
  • AymenDaoudi
    AymenDaoudi over 7 years
    I 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
    number9 over 7 years
    You clearly stated "TCP and UDP would be great". Sorry for my mis-interpretation. I will update my response.
  • AymenDaoudi
    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
    SaTa over 3 years
    I could not install netatop on ubuntu 20.04. Do you have any instructions?
  • John Greene
    John Greene over 3 years
    Does not show PID.