#!/bin/sh
#------------------------------------------------------------------------------
# OPT_QOS       /etc/rrdtool/qos.val                               __FLI4LVER__
# Creation:     bastard
# Last Update:  $Id$
#------------------------------------------------------------------------------

[ -z "$RDTOOL_CONF_LOADED" ] && . /var/run/rrdtool.conf

local source=qos
eval local idx='$RRDTOOL_'$source'_ID'
eval local options='$RRDTOOL_'$idx'_OPTIONS_STRING'

echo "THE TEST"

for item in $options
do
    local interface=
    local db_file=$RRDTOOL_DB_PATH/$source/$item.rrd
    case "$item" in
    "down")interface='imq0';;
    "up")  interface='imq1';;
    esac
    case "$item" in
    "down"|"up")
        if [ ! -f /var/run/rrdtool.qos.$item ]
        then
            bytes=`tc -s class show dev $interface|grep Sent|cut -d ' ' -f 3|tr '\n' ':'|sed '$s/.$//'`
            rrdtool update $db_file \
            N:$bytes
        else
            u=`for i in \`tc -s class show dev $interface|grep "class htb"|cut -d ' ' -f 3\`
            do
            echo -n U:
            done|sed '$s/.$//'`
            rrdtool update $db_file \
            N:$u
            if [ "$?" -eq "0" ]
            then
                rm /var/run/rrdtool.qos.$item
            fi
        fi
        ;;
    esac
done
