cbqmon.pl

Linux Advanced Routing and Traffic Control

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Some time ago someone posted a nice script to monitor HTB classes,
classmon.pl. A friend of mine ported it to CBQ, and attached is the
result.

Suggestions are welcome.

Rubens


> #!/usr/bin/perl
>
> # Classy CBQ Operations Monitor...in Perl
> # Based on classmon.pl by Toby Cantor
> # By BLFC
>
> # The following short command line options are parsed as you might expect.
> # There is NO error checking.  The options below are used as follows:
> #
> # -i <name of the interface to monitor>
> # -d <single EWMA parameter determines averager's "memory".  Should be
> #     positive but less than unity. Lower equates to faster response>
> # -u <number of updates per second.  Any positive value is acceptible
here,
> #     including decimals.  A value of 0.2 would update once every 5
seconds>
> # -w <a pattern which determines which classes are displayed.  May include
> #     the wildcard characters '*' and '?' and they behave as in bash>
> #
> ## EWMA is calculated every 2nd update.  This was tested on a Pentium 90,
on
> ## which the updates/second has a maximum of 6 or so.  Do the math.  The
> ## default in this case is decent.  Speaking of which...
> #
> # The defaults are first and should require no explanation.
>
> ($iface, $parm, $persec, $watchclass) = ('eth0', 0.6, 1, '*');
> while ($argument = shift @ARGV)
> {
>     if    ($argument =~ '-i')    {      $iface = shift @ARGV; }
>     elsif ($argument =~ '-d')    {       $parm = shift @ARGV; }
>     elsif ($argument =~ '-u')    {     $persec = shift @ARGV; }
>     elsif ($argument =~ '-w')    { $watchclass = shift @ARGV; }
>
> }
>
> use Term::Cap;
> use Time::HiRes qw(gettimeofday sleep);
>
> $clear = `clear`;
> $terminal = Tgetent Term::Cap;
> $origin = $terminal->Tgoto('cm',0,0);
> $origin2 = $terminal->Tgoto('cm',0,3);
>
> $printrates=0;
> $wait_time = 1/$persec - .1;
> $starttime = $oldtime = gettimeofday();
>
> $header = $origin . "$iface-$watchclass
> Class     kbps    pps  backlog  dropped borrowed overact.   tokens
ctokens
> ------ ------- ------ -------- -------- -------- -------- -------- -------
-\n";
>
> format STDOUT =
> @<<<<< @####.# @###.# @####### @####### @####### @####### @#######
@#######
> {$classid, @{$smoothed{$classid}}{'bytes','packets'},
>
@{$classdata{$classid}}{'backlog','dropped','borrowed','overactions','tokens
','ctokens'}}
> .
>
> print $clear.$header;
>
> $watchclass =~ s/\?/\./g;
> $watchclass =~ s/\*/\.\*/g;
>
> while (@allinfo = (readpipe("tc -s class show dev $iface")))
> {
> # class cbq 1: root rate 100Mbit (bounded,isolated) prio no-transmit
> #  Sent 41352703832 bytes 165540580 pkts (dropped 0, overlimits 0)
> #   borrowed 0 overactions 0 avgidle 58 undertime 0
> # class cbq 1:1990 parent 1: leaf 1990: rate 4000Kbit (bounded) prio
no-transmit
> #  Sent 22013154608 bytes 33663376 pkts (dropped 326694, overlimits
114912551)
> #   borrowed 0 overactions 807479 avgidle 26432 undertime 0
>     foreach (@allinfo)
>     {
>         next unless /\S/;
>         chomp;
>
>         next if ((/class cbq/ && ($classid = (split)[2])) || ($classid !~
/$watchclass/));
>         next if (/Sent/ &&
>             (@{$classdata{$classid}}{'bytes','packets','dropped'} =
(split)[1,3,6]));
> #       next if (/backlog/ && chop && chop &&
> #           ($classdata{$classid}{'backlog'} = (split)[4]));
>         next if (/borrowed/ &&
>             (@{$classdata{$classid}}{'borrowed','overactions'} =
(split)[1,3]));
> #       next if (/tokens/ &&
> #           (@{$classdata{$classid}}{'tokens','ctokens'} = (split)[1,3]));
> #       $classdata{$classid}{'backlog'} = 0;
>     }
>
>     $nowtime = gettimeofday();
>     $difftime=$nowtime-$oldtime;
>     $oldtime = $nowtime;
>
>     print $origin2;
>     foreach $classid (sort keys %classdata)
>     {
>         chop $classdata{$classid}{'dropped'};
>         $classdata{$classid}{'bytes'} *= (8/1024);
>
>         foreach $keyn ('bytes','packets')
>         {
>             last if $printrates;
>
>             $smoothed{$classid}{$keyn} =
>                 $parm * (($classdata{$classid}{$keyn} -
$olddata{$classid}{$keyn})/($nowtime - $last_time)) +
>                 (1-$parm) * $smoothed{$classid}{$keyn};
>
>             if ($nowtime-$starttime < 2/$persec) {
$smoothed{$classid}{$keyn} = 0; }
>             $olddata{$classid}{$keyn} = $classdata{$classid}{$keyn};
>         }
>
>
>     write;
>     }
>     $last_time = $nowtime unless $printrates;
>     $time_err = $difftime - 1/$persec;
>     $wait_time -= 3*$time_err/5;
>     sleep($wait_time);
>     $printrates++;
>     $printrates %=2;
> }
>
>

Attachment: cbqmon.pl
Description: Binary data


[Index of Archives]     [LARTC Home Page]     [Netfilter]     [Netfilter Development]     [Network Development]     [Bugtraq]     [GCC Help]     [Yosemite News]     [Linux Kernel]     [Fedora Users]
  Powered by Linux