in reply to Network Usage of an application

As already pointed out, it's not exactly clear what you mean, but maybe try something like this:

#!/usr/bin/perl use GTop (); my $gtop = GTop->new(); my %pre_stats; sub get_netstats { my $init = shift; my $netload = $gtop->netload("eth0"); for (qw(bytes_out bytes_in bytes_total packets_out packets_in packets_total)) { if ($init) { $pre_stats{$_} = $netload->$_(); } else { printf "%-14s: %d\n", $_, $netload->$_() - $pre_stats{$_}; } } } get_netstats("initial"); system "wget", "http://perlmonks.org"; # your app here get_netstats(); __END__ $ ./834243.pl --18:20:17-- http://perlmonks.org/ => `index.html' Resolving perlmonks.org... 66.39.54.27, 209.197.123.153 Connecting to perlmonks.org|66.39.54.27|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 83,769 (82K) [text/html] 100%[================================================================= +==========>] 83,769 118.72K/s 18:20:18 (118.47 KB/s) - `index.html' saved [83769/83769] bytes_out : 3553 bytes_in : 88978 bytes_total : 92531 packets_out : 51 packets_in : 68 packets_total : 119

Of course, as the traffic info is interface-global (not process-specific), there mustn't be any other significant network traffic going on while you're measuring...

Replies are listed 'Best First'.
Re^2: Network Usage of an application
by mld (Acolyte) on Apr 13, 2010 at 08:32 UTC

    Thanks. But not able to install the Gtop module in my system. Is this module is applicable for Windows system.In the net It has been said Gtop is used for Unix.

      Chances are it will work on windows if libgtop works on windows, and since libgtop is a gnobe library, chances are it might work on windows. :)

      Alternatively there is Win32::PerfMon/ Win32::Process::Perf which perform a similar function as libgtop.

        Thanks for your effort.Win32::PerfMon and Win32::Process::Perf are used to get the CPU cycle time not the net load (Upload and download traffic)

        on trying to install GTop using CPAN following error message is thrown

        Writing Makefile for GTop

        make' is not recognized as an internal or external command, operable program or batch file.</p

        MJH/GTop-0.16.tar.gz

        nmake -- NOT OK

        Running make test Can't test without successful make

        Running make install Make had returned bad status, install seems impossible

        Failed during this command: MJH/GTop-0.16.tar.gz : make NO