root / plugins / network / qos_ @ 92483a04
Historique | Voir | Annoter | Télécharger (4,73 ko)
| 1 | f46427c6 | Vitaly Peretiatko | #!/usr/bin/perl -w |
|---|---|---|---|
| 2 | # -*- perl -*- |
||
| 3 | # Wildcard plugin to monitor QoS queues. |
||
| 4 | # |
||
| 5 | # Requirements: |
||
| 6 | # - tc program installed and in path |
||
| 7 | # |
||
| 8 | # Parameters supported: |
||
| 9 | # |
||
| 10 | # config |
||
| 11 | # autoconf |
||
| 12 | # suggest |
||
| 13 | # |
||
| 14 | # Configurable variables |
||
| 15 | # |
||
| 16 | # tc - Override default program |
||
| 17 | # ignore_queue<n> - Queue with handle <n> not be plotted |
||
| 18 | # label_name<n> - Queue with handle <n> as defined label |
||
| 19 | 8fbe0ebe | Steve Schnepp | # update_rate - Custom update_rate, to be used with async |
| 20 | # graph_data_size - Custom graph_data_size, to be used with async & custom update_rate |
||
| 21 | f46427c6 | Vitaly Peretiatko | # |
| 22 | # Magic markers: |
||
| 23 | #%# family=manual |
||
| 24 | #%# capabilities=autoconf suggest |
||
| 25 | |||
| 26 | use strict; |
||
| 27 | |||
| 28 | my $TC = $ENV{'tc'} || 'tc';
|
||
| 29 | |||
| 30 | if ($ARGV[0] and $ARGV[0] eq 'suggest') {
|
||
| 31 | my $text = `egrep '^ *(eth|wlan|ath|ra)[0-9]+:' /proc/net/dev | cut -f1 -d:`; |
||
| 32 | print $text; |
||
| 33 | exit; |
||
| 34 | } |
||
| 35 | |||
| 36 | $0 =~ /qos_(.+)*$/; |
||
| 37 | my $IFACE = $1; |
||
| 38 | exit 2 unless defined $IFACE; |
||
| 39 | |||
| 40 | if ( exists $ARGV[0] and $ARGV[0] eq 'autoconf' ) {
|
||
| 41 | # Now see if "tc" can run |
||
| 42 | my $text = `$TC qdisc show dev $IFACE`; |
||
| 43 | if ($?) {
|
||
| 44 | if ($? == -1) {
|
||
| 45 | print "no (program $TC not found)\n"; |
||
| 46 | } else {
|
||
| 47 | print "no (program $TC died)\n"; |
||
| 48 | } |
||
| 49 | e4cd049b | Lars Kruse | } else {
|
| 50 | print "yes\n"; |
||
| 51 | f46427c6 | Vitaly Peretiatko | } |
| 52 | exit 0; |
||
| 53 | } |
||
| 54 | |||
| 55 | my %queues; |
||
| 56 | my $qdisc; |
||
| 57 | my $queue; |
||
| 58 | my $handle; |
||
| 59 | my $one; |
||
| 60 | my $sent; |
||
| 61 | my $count; |
||
| 62 | my $haschild; |
||
| 63 | |||
| 64 | #open(TEXT, "$TC -s qdisc show dev $IFACE|"); |
||
| 65 | #while (! eof(TEXT)) {
|
||
| 66 | # ($qdisc, $queue, $handle) = split(" ", <TEXT>);
|
||
| 67 | # if ($qdisc eq "backlog") {
|
||
| 68 | # ($qdisc, $queue, $handle) = split(" ", <TEXT>);
|
||
| 69 | # } |
||
| 70 | # ($one, $sent) = split(" ", <TEXT>);
|
||
| 71 | # $handle =~ s/://; |
||
| 72 | # $queues{$handle} = {
|
||
| 73 | # queue => $queue, |
||
| 74 | # handle => $handle, |
||
| 75 | # sent => $sent |
||
| 76 | # }; |
||
| 77 | #} |
||
| 78 | |||
| 79 | my @class = `$TC -s class show dev $IFACE`; |
||
| 80 | my( $name, $id1, $id2, $type, $rate, $parent); |
||
| 81 | for( my $x = 0; $x < scalar(@class); $x++ ) {
|
||
| 82 | if($class[$x] =~ m/^class/i ) {
|
||
| 83 | ( $name, $id1, $id2, $type, $parent) = ( $class[$x] =~ m/^class\s+(\w+)\s+(\d+):(\d+)\s+(\w+)\s([^\s]+)/i ); |
||
| 84 | 0553d6c2 | Samuel Smith | if($type && $type eq "parent") {
|
| 85 | f46427c6 | Vitaly Peretiatko | $x++; |
| 86 | ( $rate ) = ( $class[$x] =~ m/Sent\s+(\d+)\s+/i ); |
||
| 87 | $handle = "$name"."${id1}_${id2}";
|
||
| 88 | $queues{$handle} = {
|
||
| 89 | queue => $name, |
||
| 90 | handle => "${id1}_${id2}",
|
||
| 91 | id => "${id1}:${id2}",
|
||
| 92 | sent => $rate, |
||
| 93 | parent => $parent |
||
| 94 | }; |
||
| 95 | } |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | if ( exists $ARGV[0] and $ARGV[0] eq 'config' ) {
|
||
| 100 | print "graph_title QoS queue on $IFACE\n"; |
||
| 101 | print "graph_args --base 1000\n"; |
||
| 102 | print "graph_vlabel bits per \${graph_period}\n";
|
||
| 103 | print "graph_category network\n"; |
||
| 104 | print "graph_info This graph shows the QoS queue of the $IFACE network interface.\n"; |
||
| 105 | 8fbe0ebe | Steve Schnepp | print "update_rate $ENV{update_rate}\n" if $ENV{update_rate};
|
| 106 | print "graph_data_size $ENV{graph_data_size}\n" if $ENV{graph_data_size};
|
||
| 107 | f46427c6 | Vitaly Peretiatko | print "graph_order "; |
| 108 | foreach my $key (sort by_handle keys %queues) {
|
||
| 109 | 87efe709 | Samuel Smith | delete $queues{$key} if $key =~ /sfq/i;
|
| 110 | next if $key =~ /sfq/i; |
||
| 111 | f46427c6 | Vitaly Peretiatko | $haschild = 0; |
| 112 | foreach my $key2 (sort by_handle keys %queues) {
|
||
| 113 | if($queues{$key}->{id} eq $queues{$key2}->{parent}) {
|
||
| 114 | $haschild = 1; |
||
| 115 | last; |
||
| 116 | } |
||
| 117 | } |
||
| 118 | 17f78427 | Lars Kruse | if($haschild == 1) {
|
| 119 | f46427c6 | Vitaly Peretiatko | $queues{$key}->{leaf} = 0;
|
| 120 | 17f78427 | Lars Kruse | next; |
| 121 | f46427c6 | Vitaly Peretiatko | } |
| 122 | $queues{$key}->{leaf} = 1;
|
||
| 123 | print $queues{$key}->{queue},$queues{$key}->{handle}, " ";
|
||
| 124 | } |
||
| 125 | print "\n"; |
||
| 126 | $count = 0; |
||
| 127 | foreach my $key (sort by_handle keys %queues) {
|
||
| 128 | if($queues{$key}->{leaf} == 0) { next; }
|
||
| 129 | print $queues{$key}->{queue},$queues{$key}->{handle}, ".label ";
|
||
| 130 | if (exists $ENV{"label_name$queues{$key}->{handle}"}) {
|
||
| 131 | print $ENV{"label_name$queues{$key}->{handle}"};
|
||
| 132 | } else {
|
||
| 133 | print $queues{$key}->{queue},$queues{$key}->{handle};
|
||
| 134 | } |
||
| 135 | print "\n"; |
||
| 136 | if (exists $ENV{"max"}) {
|
||
| 137 | print $queues{$key}->{queue},$queues{$key}->{handle}, ".max ",$ENV{"max"},"\n";
|
||
| 138 | } elsif (exists $ENV{"max$queues{$key}->{handle}"}) {
|
||
| 139 | print $queues{$key}->{queue},$queues{$key}->{handle}, ".max ",$ENV{"max$queues{$key}->{handle}"},"\n";
|
||
| 140 | } |
||
| 141 | 6b94ef02 | Samuel Smith | print $queues{$key}->{queue},$queues{$key}->{handle}, ".type DERIVE\n";
|
| 142 | f46427c6 | Vitaly Peretiatko | if($count == 0){
|
| 143 | print $queues{$key}->{queue},$queues{$key}->{handle}, ".draw AREA\n";
|
||
| 144 | } else {
|
||
| 145 | print $queues{$key}->{queue},$queues{$key}->{handle}, ".draw STACK\n";
|
||
| 146 | } |
||
| 147 | print $queues{$key}->{queue},$queues{$key}->{handle}, ".cdef ", $queues{$key}->{queue},$queues{$key}->{handle}, ",8,*\n";
|
||
| 148 | if (exists $ENV{"ignore_queue$queues{$key}->{handle}"}){
|
||
| 149 | print $queues{$key}->{queue},$queues{$key}->{handle}, ".graph no\n" ;
|
||
| 150 | } else {
|
||
| 151 | $count++; |
||
| 152 | } |
||
| 153 | } |
||
| 154 | exit 0; |
||
| 155 | } |
||
| 156 | |||
| 157 | sub by_handle {
|
||
| 158 | return $a cmp $b; |
||
| 159 | } |
||
| 160 | |||
| 161 | foreach my $key (sort by_handle keys %queues) {
|
||
| 162 | 999f4347 | Samuel Smith | next if $key =~ /sfq/i; |
| 163 | f46427c6 | Vitaly Peretiatko | $haschild = 0; |
| 164 | foreach my $key2 (sort by_handle keys %queues) {
|
||
| 165 | if($queues{$key}->{id} eq $queues{$key2}->{parent}) {
|
||
| 166 | $haschild = 1; |
||
| 167 | last; |
||
| 168 | } |
||
| 169 | } |
||
| 170 | if($haschild == 1) { next; }
|
||
| 171 | print $queues{$key}->{queue},$queues{$key}->{handle}, ".value ",$queues{$key}->{sent}, "\n";
|
||
| 172 | } |
||
| 173 | # |
||
| 174 | 0553d6c2 | Samuel Smith | # vim:syntax=perl |
