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, "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; }
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.

Edited by castaway, added code tags


In reply to Perl Script for Network bandwidth consumption by a particular Application by ratul_11

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.