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