Hi
Firstly a warm wish to all of u guys a very happy new year 2008.

I have   written a script that will check the total usage of network from
eth0 and total number of concurrent connection established from eth0.
The syntax of usage of this code is following

perl network.pl eth0 and it produces the output in the following manner.

Average traffic on eth0 is: 0.00 kbytes/second
Average traffic per connection on eth0 is: 0.00 kbytes/second

The code is as following

#!/usr/bin/perl
use strict;

my $dev = shift || 'eth0';

my $traf1 = get_curr_traf();
select(undef, undef, undef, 2);
my $traf2 = get_curr_traf();

my ($conn) = grep {/connections established/} `netstat -ts`;
$conn = (split/\s+/,$conn)[1];


my $trafavg = ($traf2 - $traf1) / (2*1024);
printf "%s%10.2f%14s\n","Average traffic on $dev is:", $trafavg,
"kbytes/second";

my $traf_per_conn = $trafavg / $conn;
printf "%s%7.2f%14s\n","Average traffic per connection on $dev is:",
$traf_per_conn, "kbytes/second";

sub get_curr_traf
{
open DEV,'/proc/net/dev' or die $!;
my ($in,$out);
while(<DEV>) {
next unless /$dev:\d+/;
($in,$out) = (split)[0,8];
$in = (split/:/,$in)[1];

}
close DEV;
return $in+$out;
}



but if i want to check network bandwidth consumption by a particular
application i.e. oracle or java by using this script or some other script
written in perl then how to do this?

Thanks & Regards in Advance
Anirban Adhikary.

Reply via email to