#!/usr/bin/perl -w # Use: # # ./query-tc.pl interface:major:minor [sent|pkts] # # Example: # # ./script.pl eth0:1:60 sent # ./script.pl eth0:1:60 pkts use strict; my $tc = '/sbin/tc'; $_ = shift || die "Missing target"; my $task = shift || 'sent'; if (/(\w+):(\d+):(\d+)/) { #class htb 1:62 parent 1:60 leaf 62: prio 0 quantum 9088 rate 71Kbit ceil 141Kbit burst 1689b/8 mpu 0b cburst 1779b/8 mpu 0b level 0 # Sent 625369766 bytes 785630 pkts (dropped 29, overlimits 0) open (TC, "$tc -s -d class show dev $1 |"); my $regex = "htb $2:$3"; while () { if (/$regex/) { $_ = ; if ($task eq 'sent' and /Sent (\d+)/) { print "$1\n0\nunknown\nSent Bytes\n"; } if ($task eq 'pkts' and /(\d+) pkts/) { print "$1\n0\nunknown\nSent Packets\n"; } } } close TC; }