1 |
#!/usr/bin/perl |
2 |
use warnings; |
3 |
use strict; |
4 |
use lib $ENV{'MUNIN_LIBDIR'}; |
5 |
use Munin::Plugin; |
6 |
|
7 |
# -*- perl -*- |
8 |
|
9 |
=head1 NAME |
10 |
|
11 |
log - Plugin to monitor log files |
12 |
|
13 |
=head1 CONFIGURATION |
14 |
|
15 |
add munin user to adm group if needed to read C</var/log/*.log> |
16 |
|
17 |
[log] |
18 |
group adm |
19 |
|
20 |
=head1 MAGIC MARKERS |
21 |
|
22 |
#%# family=auto |
23 |
#%# capabilities=autoconf |
24 |
|
25 |
=cut |
26 |
|
27 |
my $log = '/var/log/daemon.log'; |
28 |
|
29 |
if ( $ARGV[0] ) { |
30 |
|
31 |
if ( $ARGV[0] eq 'autoconf' ) { |
32 |
print -r $log ? "yes\n" : "no\n"; |
33 |
} elsif ( $ARGV[0] eq 'config' ) { |
34 |
print <<EOM; |
35 |
multigraph stunnel |
36 |
graph_category log |
37 |
graph_title stunnel clients |
38 |
clients.label clients |
39 |
|
40 |
multigraph stunnel_transfer |
41 |
graph_category log |
42 |
graph_title stunnel transfer |
43 |
graph_vlabel bytes/\${graph_period} |
44 |
ssl.label SSL |
45 |
ssl.draw AREA |
46 |
socket.label Socket |
47 |
socket.draw LINE2 |
48 |
|
49 |
multigraph n2n |
50 |
graph_category log |
51 |
graph_title n2n peers |
52 |
pending.label Pending peers |
53 |
operational.label Operational peers |
54 |
|
55 |
multigraph lines |
56 |
graph_category log |
57 |
graph_title log lines |
58 |
stunnel.label stunnel |
59 |
n2n.label n2n |
60 |
ignored.label ignored |
61 |
EOM |
62 |
} |
63 |
exit 0; |
64 |
} |
65 |
|
66 |
my ( $pos ) = restore_state(); |
67 |
$pos = -s $log unless defined $pos; |
68 |
my ($fh,$reset) = tail_open($log,$pos); |
69 |
|
70 |
my $ip; |
71 |
my $stat; |
72 |
|
73 |
|
74 |
while(<$fh>) { |
75 |
if ( m/stunnel/ ) { |
76 |
$stat->{lines}->{stunnel}++; |
77 |
if ( m/accepted connection from (.+):\d+/ ) { |
78 |
$ip->{$1}++; |
79 |
} elsif ( m/Connection closed: (\d+) bytes sent to SSL, (\d+) bytes sent to socket/i ) { |
80 |
$stat->{stunnel_transfer}->{ssl} += $1; |
81 |
$stat->{stunnel_transfer}->{socket} += $2; |
82 |
} |
83 |
} elsif ( m/n2n/ ) { |
84 |
$stat->{lines}->{n2n}++; |
85 |
if ( m/Pending peers list size=(\d+)/ ) { |
86 |
$stat->{n2n}->{pending} = $1; # latest |
87 |
} elsif ( m/Operational peers list size=(\d+)/ ) { |
88 |
$stat->{n2n}->{operational} = $1; # latest |
89 |
} elsif ( m/pending=(\d+), operational=(\d+)/ ) { |
90 |
$stat->{n2n} = { pending => 1, operational => 2 }; |
91 |
} |
92 |
} else { |
93 |
$stat->{lines}->{ignored}++; |
94 |
} |
95 |
} |
96 |
|
97 |
$stat->{stunnel}->{clients} = scalar keys %$ip if $ip; |
98 |
|
99 |
foreach my $graph ( keys %$stat ) { |
100 |
print "multigraph $graph\n"; |
101 |
print "$_.value $stat->{$graph}->{$_}\n" foreach keys %{ $stat->{$graph} }; |
102 |
} |
103 |
|
104 |
$pos = tail_close($fh); |
105 |
save_state($pos); |
106 |
|