PluginCat: qos_

File qos_, 2.8 kB (added by fra519@fra519.no-ip.org, 6 years ago)

QoS script use tc program, monitor of each queue attached on specified network device, see script for env configuration.

Line 
1 #!/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> (ex ignore_queue0 for root queue) not be plotted
18 #       label_name<n>     - Queue with handle <n> as define label
19 #
20 # $Log$
21 # Revision 1.1  2006/03/05 17:11:36  fra519
22 #
23 #
24 # Magic markers:
25 #%# family=manual
26 #%# capabilities=autoconf suggest
27
28 use strict;
29
30 my $TC = $ENV{'tc'} || 'tc';
31
32 if ($ARGV[0] and $ARGV[0] eq 'suggest') {
33   my $text = `egrep '^ *(eth|wlan|ath|ra)[0-9]+:' /proc/net/dev | cut -f1 -d:`;
34   print $text;
35   exit;
36 }
37
38 $0 =~ /qos_(.+)*$/;
39 my $IFACE = $1;
40 exit 2 unless defined $IFACE;
41
42 if ( exists $ARGV[0] and $ARGV[0] eq 'autoconf' ) {
43   # Now see if "tc" can run
44   my $text = `$TC qdisc show dev $IFACE`;
45   if ($?) {
46     if ($? == -1) {
47       print "no (program $TC not found)\n";
48     } else {
49       print "no (program $TC died)\n";
50     }
51     exit 1;
52   }
53   print "yes\n";
54   exit 0;
55 }
56
57 my %queues;
58 my $qdisc;
59 my $queue;
60 my $handle;
61 my $one;
62 my $sent;
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 if ( exists $ARGV[0] and $ARGV[0] eq 'config' ) {
80   print "graph_title QoS queue on $IFACE\n";
81   print "graph_args --base 1000\n";
82   print "graph_vlabel bits per \${graph_period}\n";
83   print "graph_category network\n";
84   print "graph_info This graph shows the QoS queue of the $IFACE network interface.\n";
85   print "graph_order ";
86   foreach my $key (sort by_handle keys %queues) {
87     print $queues{$key}->{queue},$queues{$key}->{handle}, " ";
88   }
89   print "\n";
90   foreach my $key (sort by_handle keys %queues) {
91     print $queues{$key}->{queue},$queues{$key}->{handle}, ".label ";
92     if (exists $ENV{"label_name$queues{$key}->{handle}"}) {
93       print $ENV{"label_name$queues{$key}->{handle}"};
94     } else {
95       print $queues{$key}->{queue},$queues{$key}->{handle};
96     }
97     print "\n";
98     print $queues{$key}->{queue},$queues{$key}->{handle}, ".type COUNTER\n";
99     print $queues{$key}->{queue},$queues{$key}->{handle}, ".graph no\n" if exists $ENV{"ignore_queue$queues{$key}->{handle}"};
100     print $queues{$key}->{queue},$queues{$key}->{handle}, ".cdef ", $queues{$key}->{queue},$queues{$key}->{handle}, ",8,*\n";
101   }
102   exit 0;
103 }
104
105 sub by_handle {
106   return $a cmp $b;
107 }
108
109 foreach my $key (sort by_handle keys %queues) {
110   print $queues{$key}->{queue},$queues{$key}->{handle}, ".value ",$queues{$key}->{sent}, "\n";
111 }
112 #
113 # vim:syntax=perl