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...


In reply to Re: Network Usage of an application by almut
in thread Network Usage of an application by mld

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.