ratul_11 has asked for the wisdom of the Perl Monks concerning the following question:
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.#!/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, "kbyt +es/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; }
Edited by castaway, added code tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl Script for Network bandwidth consumption by a particular Application
by TOD (Friar) on Jan 02, 2008 at 10:21 UTC |