[LARTC] tc statistics

Simon Stemplinger Simon.Stemplinger@gmx.de
Wed, 02 Jul 2003 15:08:50 +0200


Joerg Hartmann wrote:
> Hello,
> 
> i have to write a script to visualize the output of tc -s class show dev 
> eth0 with rrdtool.
> Or does anybody know of such a script , which is available for download ?
> 
> I assume the bps in "rate 5728bps 34pps" is Byte per Second.
> Is that right ?
> How can i set all the counters back to zero ?
> I did not found anything in the manpage of tc.
> 
> regards
> 			Joerg

Hi Joerg,

i use this script.  It is not yet complete and as I am not very good in 
shell programming, you can probably do better, but it works ;-)

regards,
	Simon


---- snip -----
#!/bin/bash

TC=/root/bin/tc
CLASS=$2

usage ()
{
   echo
   echo "Usage: $0 option class"
   echo
   echo "  Options:  -r   show rate"
#  echo "            -s   show avg packet size"
   echo
   exit
}

# print uptime and hostname
printuptime ()
{
   test -z "$(uptime|grep day)" && echo 0 days
   test -z "$(uptime|grep day)" || echo $(uptime | awk {'print $3'}) days
   hostname
}

# an error has happened... return 0 traffic
error ()
{
   echo 0
   echo 0
   printuptime
   exit
}


rate()
{
   RATE=`echo $STATS|cut -f2 -d' '`
   echo $RATE
   echo 0
   printuptime
   exit
}

# read info about class
test -z $CLASS && usage
STATS=`$TC -s class ls dev ppp0|grep -A1 $CLASS|grep Sent`

# parse arguments
test $1 == "-r" && rate
#test $1 == "-s" && size

# else
usage