This is a multi-part message in MIME format. ------=_NextPart_000_0023_01C30C1C.9E4E6020 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit ----- Original Message ----- From: "Jannes Faber" <jannes@elevate.nl> To: "Stef Coene" <stef.coene@docum.org>; <pturley@rocksteady.com>; <lartc@mailman.ds9a.nl> Sent: Saturday, April 26, 2003 3:07 AM Subject: Re: [LARTC] Testing traffic control > I've been using TC and HTB for a while now (almost a year). Took a while to > get it running, but it's ok now (playing CounterStrike on one PC while two > others are using DirectConnect and Emule are fully using the upstream and > downstream). > > Anyway, until recently I was doing it all blind, using iptraf for some rough > indication of some total values, but that was about it. So I decided it was > time to make some graphs. So I made a simple perl script (ahum... actually I > ripped apart a script made by Stef and added my own stuff) using rrdtool to > store and display all the data. > > I attached it. You'll have to edit it a little for your own situation, but > it's quite flexible. (I'm not a perl programmer, so expect some ugly C > constructions). > > Basic commands: > > rrd_tc without parameters gives some help. But basically you call > "rrd_tc.pl create" once to create a new database. Then you run "rrd_tc.pl > collect" and keep it running in the background (nohup or in /etc/rc.local) > to collect the actual data. Then you use "rrd_tc.pl graph xv stack > update=10" to display a nice graph and have it updated every 10 seconds. > > This script stores and displays the counters for all the different TC > classes as well as the total up and download from /proc/net/dev. > > Jannes Faber > > > On Friday 25 April 2003 23:57, Patrick Turley wrote: > > > through each connection. Have the other computer display the rate at > > > which data is being received for each connection in a really cool > > > graphical way. > > > > > > Does anyone here actually have the tools to do this? I would be terribly > > > grateful if anyone could point me in the right direction. > > Stef wrote: > > I have some scripts. You can find them on www.docum.org. They don't look > > really cool, but they can show you what's going on in real-time. > > > > I have a script that uses iptables counters. An other uses the tc > counters. > > They are both shell scripts and I use them to automate my tests. > > > > I also have some scripts to store the tc counters in a rrd database so you > can > > graph long term statistics. And I have written a java applet so you can > see > > real-time graphs. > > > > Stef > > ------=_NextPart_000_0023_01C30C1C.9E4E6020 Content-Type: application/octet-stream; name="rrd_tc.pl" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="rrd_tc.pl" #!/usr/bin/perl=0A= =0A= # Default values (can also be set on the command line)=0A= $arg{sleep} =3D "10" ; # seconds between readings=0A= $arg{dev} =3D "eth0";=0A= $arg{tc} =3D "tc-htb";=0A= $arg{db} =3D "/var/local/tc.rrd";=0A= $arg{file} =3D "/tmp/rrd_tc_graph.png";=0A= $arg{time} =3D "1200";=0A= =0A= $max=3D200000;=0A= =0A= foreach my $arg (@ARGV) {=0A= @split =3D split ( "=3D", $arg) ;=0A= $arg{$split[0]} =3D ($split[1] eq "" ? 1 : $split[1]);=0A= }=0A= if ( $arg{create} ) {=0A= system( "test -e $arg{db} && rm -i ". $arg{db});=0A= system( "rrdtool create $arg{db} -s ". $arg{sleep}=0A= . " DS:speed_up:COUNTER:60:U:$max"=0A= . " DS:speed_dn:COUNTER:60:U:$max"=0A= . " DS:speed_1_1:COUNTER:60:U:$max"=0A= . " DS:speed_1_10:COUNTER:60:U:$max"=0A= . " DS:speed_1_11:COUNTER:60:U:$max"=0A= . " DS:speed_1_12:COUNTER:60:U:$max"=0A= . " DS:speed_1_13:COUNTER:60:U:$max"=0A= . " DS:speed_1_14:COUNTER:60:U:$max"=0A= . " RRA:AVERAGE:0.5:1:" . (12 * 30)=0A= . " RRA:AVERAGE:0.5:12:" . (60 * 2)=0A= . " RRA:AVERAGE:0.5:120:" . (6 * 12)=0A= . " RRA:AVERAGE:0.5:720:" . (24 * 7)=0A= . " RRA:AVERAGE:0.5:". (720 * 24) .":". (365)=0A= );=0A= }=0A= elsif ( $arg{graph} ) {=0A= $type0 =3D ($arg{stack} ? "AREA" : "LINE3");=0A= $type1 =3D ($arg{stack} ? "STACK" : "LINE2");=0A= $type2 =3D ($arg{stack} ? "STACK" : "LINE1");=0A= do {=0A= system( "rrdtool graph ". $arg{file} . ($arg{update} eq "" ? "" : " = -z ") =0A= . " -s -$arg{time} -e -$arg{sleep} --step 5 -w 600 -h 300 -t = \"Traffic ($arg{dev})\" -v \"byte/s\""=0A= . ($arg{stack}=0A= ? ""=0A= : " DEF:speed_1_1=3D$arg{db}:speed_1_1:AVERAGE = AREA:speed_1_1#22ff22:\"1_1 (total)\""=0A= )=0A= . " DEF:speed_1_10=3D$arg{db}:speed_1_10:AVERAGE = $type0:speed_1_10#aaaaaa:\"1_10 (cs)\""=0A= . " DEF:speed_1_11=3D$arg{db}:speed_1_11:AVERAGE = $type1:speed_1_11#000000:\"1_11 (ssh)\""=0A= . " DEF:speed_1_12=3D$arg{db}:speed_1_12:AVERAGE = $type1:speed_1_12#ff0000:\"1_12 (www)\""=0A= . " DEF:speed_1_13=3D$arg{db}:speed_1_13:AVERAGE = $type1:speed_1_13#66ffff:\"1_13 (ack)\""=0A= . " DEF:speed_1_14=3D$arg{db}:speed_1_14:AVERAGE = $type2:speed_1_14#0000aa:\"1_14 (rest)\""=0A= . " DEF:speed_up=3D$arg{db}:speed_up:AVERAGE = LINE1:speed_up#aa0000:\"Total UP\""=0A= . " DEF:speed_dn=3D$arg{db}:speed_dn:AVERAGE"=0A= . " CDEF:speed_dn10=3Dspeed_dn,10,/ = LINE1:speed_dn10#00aa00:\"Total DOWN/10\""=0A= . " > /dev/null"=0A= );=0A= if($arg{xv}) {=0A= system("xv +nopos -dr 0 0 -poll ". $arg{file} ." &");=0A= $arg{xv} =3D "";=0A= }=0A= sleep($arg{update});=0A= } while($arg{update});=0A= }=0A= elsif ( $arg{collect} ) {=0A= main () ;=0A= }=0A= else {=0A= print " $0 create [sleep=3DSEC] [db=3DFILE]\n"=0A= . " $0 collect [sleep=3DSEC] [db=3DFILE] [dev=3DDEV] [tc=3DFILE]\n"=0A= . " $0 graph [xv] [stack] [time=3DSEC] [update=3DSEC] [file=3DFILE] = [db=3DFILE]\n"=0A= ;=0A= }=0A= =0A= sub main {=0A= format STDOUT_TOP =3D=0A= Classid tokens ctokens bytes speed=0A= ------------------------------------------=0A= .=0A= format STDOUT =3D=0A= @<<<<<<<< @<<<<<<<<@<<<<<< @<<<<< @<<<<<<<=0A= $classid $tokens $ctokens $Sent $speed=0A= .=0A= =0A= while (1) {=0A= my $flds=3D"";=0A= my $vals=3D"";=0A= =0A= my %acc =3D get_proccounters();=0A= $flds .=3D "speed_up:speed_dn";=0A= $vals .=3D "$acc{up}:$acc{dn}";=0A= =0A= my %acc =3D get_counters () ;=0A= =0A= foreach $key (keys(%acc)) {=0A= $classid =3D $key;=0A= $tokens =3D $acc{$key}{tokens} ;=0A= $ctokens =3D $acc{$key}{ctokens} ;=0A= $Sent{$key} =3D $acc{$key}{Sent} - $acc_vorige{$key}{Sent} ;=0A= $Sent =3D $Sent{$key} ;=0A= # write ;=0A= =0A= $classid =3D~ s/:/_/;=0A= $flds .=3D ($flds eq "" ? "" : ":") ."speed_". $classid;=0A= $vals .=3D ($vals eq "" ? "" : ":") . $acc{$key}{Sent};=0A= }=0A= system("rrdtool update $arg{db} -t ". $flds ." N:". $vals );=0A= sleep ($arg{sleep}) ;=0A= } }=0A= =0A= sub get_counters {=0A= my %ACC ;=0A= my @class =3D `$arg{tc} -s -d class show dev $arg{dev}` ; # Get all = class info=0A= =0A= foreach my $ele (@class) {=0A= chomp ($ele) ;=0A= my @temp =3D split(" ",$ele) ;=0A= my $i =3D 0 ;=0A= foreach my $temp (@temp) {=0A= $i ++ ;=0A= if ( $temp eq "htb" ) {=0A= $classid =3D $temp[$i] ;=0A= } elsif ( $temp =3D~ /\d/ ) {=0A= #print "classid $classid $name $temp\n" ;=0A= $ACC{$classid}{$name} =3D $temp ;=0A= } else {=0A= $temp =3D~ s/://g ;=0A= $temp =3D~ s/\(//g ;=0A= $name =3D $temp ;=0A= }=0A= }=0A= }=0A= return %ACC ;=0A= }=0A= =0A= sub get_proccounters {=0A= my %ACC;=0A= my @counters =3D `cat /proc/net/dev | grep $arg{dev}`;=0A= my @temp =3D split(":",$counters[0]);=0A= chomp($temp[1]);=0A= my @temp =3D split(" ", $temp[1]);=0A= $ACC{dn} =3D $temp[0];=0A= $ACC{up} =3D $temp[8];=0A= return %ACC;=0A= }=0A= ------=_NextPart_000_0023_01C30C1C.9E4E6020--