File: tc.in

package info (click to toggle)
munin 2.0.76-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,064 kB
  • sloc: perl: 11,684; java: 1,924; sh: 1,632; makefile: 636; javascript: 365; python: 267
file content (179 lines) | stat: -rw-r--r-- 4,316 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!@@PERL@@
# -*-  perl -*-

=head1 NAME

tc - plugin to monitor traffic control queues

=head1 APPLICABLE SYSTEMS

Every Linux system with tc configured.

=head1 CONFIGURATION

This plugin automatically detects the queues that are configured.

To specify the location of the tc command, set the tc environment variable.
For example:

  [tc]
  env.tc /sbin/tc

=head1 USAGE

Link this plugin to @@CONFDIR@@/plugins/ and restart the munin-node.

=head1 MAGIC MARKERS

  #%# family=auto
  #%# capabilities=autoconf

=head1 BUGS

None known.

=head1 AUTHOR

Brian De Wolf

=head1 LICENSE

GPLv2

=cut


use warnings;
use strict;

use Munin::Plugin;

my $TC = ($ENV{tc} or
            (-x "/sbin/tc" and "/sbin/tc") or
            (-x "/usr/sbin/tc" and "/usr/sbin/tc"));
my $mode = ($ARGV[0] or "print");

open(TC, "$TC -s qdisc |")
    or die "Failed to run $TC: $!";

my %qdiscs;
my $autoconf = "no";

my $current_qdisc;
while(<TC>) {
    chomp;
    my $raw = $_;
# An example:
#qdisc pfifo_fast 0: dev eth1 root refcnt 2 bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
    if(/^qdisc/) {
        my (undef, $type, $name, undef, $dev) = split(/ /);

        # Most linux boxes will have qdiscs, but they'll all be pfifo_fast.  If
        # we see one that isn't, it implies someone configured tc and would be
        # interested in our graphs.
        $autoconf = "yes"
            if $type ne "pfifo_fast";

        $current_qdisc = clean_fieldname("${dev}_$name");
        $qdiscs{$current_qdisc}{raw} = $raw;
        $qdiscs{$current_qdisc}{name} = "$dev $name";
# Sent 554351897174 bytes 265755405 pkt (dropped 19943, overlimits 0 requeues 1766011)
    } elsif(/^ Sent/) {
        # split on non-digits, leaving us with just the numbers
        my (undef, $bytes, $packets, $dropped, $overlimit, $requeues) = split(/\D+/, $raw);
        $qdiscs{$current_qdisc}{bytes} = $bytes;
        $qdiscs{$current_qdisc}{packets} = $packets;
        $qdiscs{$current_qdisc}{dropped} = $dropped;
        $qdiscs{$current_qdisc}{overlimit} = $overlimit;
        $qdiscs{$current_qdisc}{requeues} = $requeues;
    }
}

close TC
    or die "$TC returned error on exit: $!";

if($mode eq 'autoconf') {
    print "$autoconf\n";
    exit 0;
}

# Print overview graphs
foreach my $type (qw(bps pps dps ops rps)) {
    print "\nmultigraph tc_$type\n";
    my ($unit, $stat);
    if($type eq "bps") {
        $unit = "bits";
        $stat = "bytes";
    } elsif($type eq "pps") {
        $unit = "packets";
        $stat = "packets";
    } elsif($type eq "dps") {
        $unit = "dropped packets";
        $stat = "dropped";
    } elsif($type eq "ops") {
        $unit = "overlimit packets";
        $stat = "overlimit";
    } elsif($type eq "rps") {
        $unit = "requeued packets";
        $stat = "requeues";
    }
    if($mode eq 'config') {
        print <<EOF;
graph_title Traffic control $unit per second per qdisc
graph_args --base 1000
graph_vlabel $unit per second
graph_category network

EOF
        print "graph_order";
        foreach my $qdisc (keys %qdiscs) {
            print " $qdisc\_$type=tc_$type.$qdisc.$qdisc\_$type";
        }
        print "\n\n";
    }
    foreach my $qdisc (keys %qdiscs) {
        my $fname = "${qdisc}_$type";
        if($mode eq 'config') {
            print <<EOF;
$fname.label $qdiscs{$qdisc}{name}
$fname.type DERIVE
$fname.min 0
$fname.update no
$fname.draw LINE1
$fname.info $qdiscs{$qdisc}{raw}
EOF
            print "$fname.cdef $fname,8,*\n"
                if($type eq 'bps');
            print_thresholds($fname);
        } else {
            print "$fname.value $qdiscs{$qdisc}{$stat}\n";
        }
    }

    # Singleton graphs
    foreach my $qdisc (keys %qdiscs) {
        my $fname = "${qdisc}_$type";
        print "\nmultigraph tc_$type.$qdisc\n";
        if($mode eq 'config') {
            print <<EOF;
graph_title $qdiscs{$qdisc}{name} $unit per second
graph_args --base 1000
graph_vlabel $unit per second
graph_category network

$fname.label $qdiscs{$qdisc}{name} $type
$fname.type DERIVE
$fname.min 0
$fname.info $qdiscs{$qdisc}{raw}
$fname.draw AREA
EOF
            print "$fname.cdef $fname,8,*\n"
                if($type eq 'bps');
        } else {
            print "$fname.value $qdiscs{$qdisc}{$stat}\n";
        }
    }
}


# vim: ft=perl sw=4 ts=4 et