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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
#!/usr/bin/perl
###
# based on https://gallery.munin-monitoring.org/plugins/munin-contrib/bird/
# which itself seems to be based on https://github.com/luben/bird-multigraph-plugin
##
use IO::Socket::UNIX;
use Munin::Plugin;
use strict;
use warnings;
use v5.10;
# get rid of some variables
use feature qw( switch );
no if $] >= 5.018, warnings => qw( experimental::smartmatch );
=head1 NAME
bird - Munin multigraph plugin to monitor BIRD routing daemon activity
=head1 APPLICABLE SYSTEMS
Every system with running bird
=head1 CONFIGURATION
The plugin must run with a user or group that could connect to bird
control socket.
This configuration snipplet is an example with the defaults:
[bird]
user root
env.protocols BGP
env.socket /var/run/bird.ctl
=head1 USAGE
Link this plugin to /etc/munin/plugins/ and restart the munin-node.
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=head1 BUGS
Not known
=head1 AUTHOR
Luben Karavelov (karavelov at mail.bg)
=head1 LICENSE
Same as perl
=cut
need_multigraph();
my $protocols = [ split(/ /, $ENV{'protocols'} || 'BGP') ];
my $socket = $ENV{'socket'} || '/var/run/bird/bird.ctl';
sub get_stats {
state $stats;
return $stats if defined $stats;
my $bird_ctl = IO::Socket::UNIX->new(
Type => SOCK_STREAM,
Peer => $socket
) or die $!;
my ($protocol,$name);
while (my $var = <$bird_ctl>) {
given($var) {
when (/1002-(\w+)\s+(\w+)\s+.*/) {
($name, $protocol) = ($1,$2);
next unless $protocol ~~ $protocols;
$stats->{$name}->{protocol} = $protocol;
# fix uninit variables
$stats->{$name}->{title} = $name;
$stats->{$name}->{imported} = 0;
$stats->{$name}->{filtered} = 0;
$stats->{$name}->{exported} = 0;
$stats->{$name}->{preferred} = 0;
}
when (/^0001 /) {
print $bird_ctl "show protocols all\n";
next;
}
when (/^0000 /) {
last;
}
when (/^1002- /) {
print;
}
when (/^1006-\s+Description:\s+(.+)$/){
next unless $protocol ~~ $protocols;
$stats->{$name}->{title} = $1;
}
# no filtered present
when (/^\s+Routes:\s+(\d+)\s+imported,\s+(\d+)\s+exported,\s+(\d+)\s+preferred$/){
next unless $protocol ~~ $protocols;
$stats->{$name}->{imported} = $1;
$stats->{$name}->{filtered} = 0;
$stats->{$name}->{exported} = $2;
$stats->{$name}->{preferred} = $3;
}
# filtered present
when (/^\s+Routes:\s+(\d+)\s+imported,\s+(\d+)\s+filtered,\s+(\d+)\s+exported,\s+(\d+)\s+preferred$/){
next unless $protocol ~~ $protocols;
$stats->{$name}->{imported} = $1;
$stats->{$name}->{filtered} = $2;
$stats->{$name}->{exported} = $3;
$stats->{$name}->{preferred} = $4;
}
# received rejected filtered ignored accepted
when (/^\s+(Import|Export)\s(updates|withdraws):\s+(\d+|-+)\s+(\d+|-+)\s+(\d+|-+)\s+(\d+|-+)\s+(\d+|-+)$/){
next unless $protocol ~~ $protocols;
$stats->{$name}->{ lc("$1_$2_received") } = $3;
$stats->{$name}->{ lc("$1_$2_rejected") } = $4;
$stats->{$name}->{ lc("$1_$2_filtered") } = $5;
$stats->{$name}->{ lc("$1_$2_ignored" ) } = $6;
$stats->{$name}->{ lc("$1_$2_accepted") } = $7;
}
when (/^$/) {
undef $protocol;
undef $name;
}
}
}
$bird_ctl->close;
return $stats;
}
sub autoconf {
if (-S $socket) {
say 'yes';
} else {
say 'no';
}
exit 0;
}
sub config {
my $stats = get_stats;
while ( my ($name,$proto) = each %$stats) {
print <<HEREDOC;
multigraph ${name}_routes
graph_title bird routes for $proto->{title}
graph_args --base 1000
graph_vlabel routes
graph_category network
exported.label Exported routes
exported.type GAUGE
exported.info Exported routes
exported.min 0
exported.draw LINE1
filtered.label Filtered routes
filtered.type GAUGE
filtered.info Filtered routes
filtered.min 0
filtered.draw LINE1
imported.label Imported routes
imported.type GAUGE
imported.info Impored routes
imported.min 0
imported.draw LINE1
preferred.label Preferred routes
preferred.type GAUGE
preferred.info Preferred routes
preferred.min 0
preferred.draw LINE1
HEREDOC
print <<HEREDOC;
multigraph ${name}_activity
graph_title bird activity for $proto->{title}
graph_args --base 1000
graph_vlabel routes per second
graph_category network
import_updates_received.label Import updates received
import_updates_received.type DERIVE
import_updates_received.draw LINE1
import_updates_rejected.label Import updates rejected
import_updates_rejected.type DERIVE
import_updates_rejected.draw LINE1
import_updates_filtered.label Import updates filtered
import_updates_filtered.type DERIVE
import_updates_filtered.draw LINE1
import_updates_ignored.label Import updates ignored
import_updates_ignored.type DERIVE
import_updates_ignored.draw LINE1
import_updates_accepted.label Import updates accepted
import_updates_accepted.type DERIVE
import_updates_accepted.draw LINE1
import_withdraws_received.label Import withdraws_received
import_withdraws_received.type DERIVE
import_withdraws_received.draw LINE1
import_withdraws_rejected.label Import withdraws rejected
import_withdraws_rejected.type DERIVE
import_withdraws_rejected.draw LINE1
import_withdraws_ignored.label Import withdraws ignored
import_withdraws_ignored.type DERIVE
import_withdraws_ignored.draw LINE1
import_withdraws_accepted.label Import withdraws accepted
import_withdraws_accepted.type DERIVE
import_withdraws_accepted.draw LINE1
export_updates_received.label Export updates received
export_updates_received.type DERIVE
export_updates_received.draw LINE1
export_updates_rejected.label Export updates rejected
export_updates_rejected.type DERIVE
export_updates_rejected.draw LINE1
export_updates_filtered.label Export updates filtered
export_updates_filtered.type DERIVE
export_updates_filtered.draw LINE1
export_updates_accepted.label Export updates accepted
export_updates_accepted.type DERIVE
export_updates_accepted.draw LINE1
export_withdraws_received.draw LINE1
export_withdraws_received.label Export withdraws received
export_withdraws_received.type DERIVE
export_withdraws_accepted.label Export withdraws accepted
export_withdraws_accepted.type DERIVE
export_withdraws_accepted.draw LINE1
HEREDOC
}
}
sub fetch {
my $stats = get_stats;
while ( my ($name,$proto) = each %$stats) {
print <<HEREDOC;
multigraph ${name}_routes
exported.value $proto->{exported}
filtered.value $proto->{filtered}
imported.value $proto->{imported}
preferred.value $proto->{preferred}
multigraph ${name}_activity
import_updates_received.value $proto->{import_updates_received}
import_updates_rejected.value $proto->{import_updates_rejected}
import_updates_filtered.value $proto->{import_updates_filtered}
import_updates_ignored.value $proto->{import_updates_ignored}
import_updates_accepted.value $proto->{import_updates_accepted}
import_withdraws_received.value $proto->{import_withdraws_received}
import_withdraws_rejected.value $proto->{import_withdraws_rejected}
import_withdraws_ignored.value $proto->{import_withdraws_ignored}
import_withdraws_accepted.value $proto->{import_withdraws_accepted}
export_updates_received.value $proto->{export_updates_received}
export_updates_rejected.value $proto->{export_updates_rejected}
export_updates_filtered.value $proto->{export_updates_filtered}
export_updates_accepted.value $proto->{export_updates_accepted}
export_withdraws_received.value $proto->{export_withdraws_received}
export_withdraws_accepted.value $proto->{export_withdraws_accepted}
HEREDOC
}
}
given ($ARGV[0]) {
when ('autoconf') { autoconf }
when ('config') { config }
default { fetch }
}
|