SourceForge.net Logo

D.12. /usr/bin/tcstat

#!/usr/bin/awk -f
# 
# GPL $Id: tcstat,v 1.1 2005/10/09 16:39:07 cvonk Exp $

# script to show the traffic control status in bar graphs
# called from /etc/init.d/tc

BEGIN {
    FS=" ";
    RS="";
}

$1 == "class" {
    if ( $3 == "1:1" ) {
	class = "root";
	guaranteed[class]=$6;
	ceil[class]=$8;
	current[class]=$25;
    } else {
	class = $3;
	guaranteed[class]=$11;
	ceil[class]=$13;
	current[class]=$30;
    }
    next;
}

END {
    totalwidth=40;

    printf("class");
    for ( ii = 0 ; ii < totalwidth ; ii++ ) {
	printf(" ");
    }
    printf("   curren guaran ceilin\n");

    for( idx in guaranteed ) {
	current_width=current[idx] * totalwidth / uplink;
	guaranteed_width=guaranteed[idx] * totalwidth / uplink;
	ceil_width=ceil[idx] * totalwidth / uplink;
	
	printf("%s  ", idx);
	for ( ii = 0; ii < totalwidth ; ii++ ) {
	    if ( ii < current_width ) {
		if( ii < guaranteed_width ) {
		    printf("#");
		} else if ( ii < ceil_width ) {
		    printf("=");
		} else {
		    printf("-");
		}
	    } else {
		printf(" ");
	    }
	}
	
	printf("  %5.1f%% %5.1f%% %5.1f%%\n",
	       current[idx] * 100 / uplink,
	       guaranteed[idx] * 100 / uplink,
	       ceil[idx] * 100 / uplink );
    }
}

# 

Example D.12. /usr/bin/tcstat