Measuring Python script bandwidth usage

5,364

Solution 1

If you are looking for a network monitor that runs as an external process and can provide per-connection statistics on the number of transferred bytes, then IPTraf can do that.

Take a look at the example screenshots, especially the TCP/UDP statistical breakdown.

Solution 2

nethogs now allows to show cumulative bandwidth usage. Just press "m".

usage: nethogs [-V] [-h] [-b] [-d seconds] [-v mode] [-c count] [-t] [-p] [-s] [-a] [-l] [-f filter][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.
                -l : display command line.
                -a : monitor all devices, even loopback/stopped ones.
                -f : EXPERIMENTAL: specify string pcap filter (like tcpdump). This may be removed orchanged in a future version.
                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
 l: display command line
 m: switch between total (KB, B, MB) and KB/s mode
Share:
5,364

Related videos on Youtube

user779420
Author by

user779420

Updated on September 18, 2022

Comments

  • user779420
    user779420 almost 2 years

    I have a python script that uses urllibs to parse some web pages, and uses selenium to scrape pages with javascript, and I would like to know its cumulative bandwidth usage. I've looked at nethogs, but its tells me the usage per second, but won't tell me how much data the script has received or sent on eth0, for example.

    Ideally, I would want it to track all new processes after I start monitoring, and then keep a table of what each process has used as a total.

    Does such a tool exist? If not, is there a library in Python that I can implement in the script to track this?

    • user779420
      user779420 about 13 years
      what did you change?
    • Gilles 'SO- stop being evil'
      Gilles 'SO- stop being evil' about 13 years
      Trickle is a tool to limit the bandwidth of a process or a bunch of processes. It has everything in hand to compute what you want, but doesn't seem to have a way to print it out.
    • Wonka
      Wonka almost 6 years
      Hey @user779420, did u resolve this problem? (7 years later I have the same requeriment)
  • Grzegorz Wierzowiecki
    Grzegorz Wierzowiecki over 12 years
    Someone might be interested in fork of IPTraf , which is IPTraf-ng.