root / plugins / network / pgld @ 6898ae6d
Historique | Voir | Annoter | Télécharger (2,07 ko)
| 1 |
#!/usr/bin/env perl |
|---|---|
| 2 |
# -*- perl -*- |
| 3 |
|
| 4 |
=head1 NAME |
| 5 |
|
| 6 |
pgld - Plugin to monitor Peer Guardian Linux blockrates |
| 7 |
|
| 8 |
=head1 CONFIGURATION |
| 9 |
|
| 10 |
[pgld] |
| 11 |
env.pgldlog /var/log/pgl/pgld.log |
| 12 |
|
| 13 |
=head1 LICENSE |
| 14 |
|
| 15 |
GPLv2 |
| 16 |
|
| 17 |
=head1 AUTHOR |
| 18 |
|
| 19 |
Daniel Lee <Longinus00@gmail.com> |
| 20 |
|
| 21 |
=head1 MAGICK MARKERS |
| 22 |
|
| 23 |
#%# family=network |
| 24 |
#%# capabilities=autoconf |
| 25 |
|
| 26 |
=cut |
| 27 |
|
| 28 |
use strict; |
| 29 |
use warnings; |
| 30 |
use Munin::Plugin; |
| 31 |
|
| 32 |
my $LOG = $ENV{'pgldlog'} || '/var/log/pgl/pgld.log';
|
| 33 |
|
| 34 |
sub trim {
|
| 35 |
my $string = shift; |
| 36 |
$string =~ s/^\s+//; |
| 37 |
$string =~ s/\s+$//; |
| 38 |
return $string; |
| 39 |
} |
| 40 |
|
| 41 |
sub autoconf {
|
| 42 |
if(-r $LOG) {
|
| 43 |
print "yes\n"; |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
sub config {
|
| 48 |
print << "EOF"; |
| 49 |
graph_title Peer Guardian hits |
| 50 |
graph_info This graph shows the number of connections blocked per minute |
| 51 |
graph_args --base 1000 -l 0 |
| 52 |
graph_vlabel hits per minute |
| 53 |
graph_category network |
| 54 |
graph_period minute |
| 55 |
hits.label hits |
| 56 |
hits.type DERIVE |
| 57 |
hits.min 0 |
| 58 |
EOF |
| 59 |
} |
| 60 |
|
| 61 |
if($ARGV[0] and $ARGV[0] eq "autoconf") {
|
| 62 |
autoconf |
| 63 |
} |
| 64 |
elsif($ARGV[0] and $ARGV[0] eq "config") {
|
| 65 |
config |
| 66 |
} |
| 67 |
else {
|
| 68 |
my $IP4 = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
|
| 69 |
my %positions = restore_state(); |
| 70 |
|
| 71 |
if(! -r $LOG) {
|
| 72 |
print "can't open $LOG for reading.\n"; |
| 73 |
} |
| 74 |
elsif( exists $positions{$LOG} ) {
|
| 75 |
my $count = 0; |
| 76 |
if( (stat $LOG)[7] < $positions{$LOG} ) {
|
| 77 |
my($fh_old, undef) = tail_open("$LOG.1", $positions{$LOG});
|
| 78 |
while(<$fh_old>) {
|
| 79 |
if( m/(IN|OUT): $IP4:\d+/ ) {
|
| 80 |
$count = $count + 1; |
| 81 |
} |
| 82 |
} |
| 83 |
$positions{$LOG} = tail_close($fh_old);
|
| 84 |
} |
| 85 |
my($fh, undef) = tail_open($LOG, $positions{$LOG});
|
| 86 |
while(<$fh>) {
|
| 87 |
if( m/(IN|OUT): $IP4:\d+\s*/ ) {
|
| 88 |
$count = $count + 1; |
| 89 |
} |
| 90 |
} |
| 91 |
$positions{$LOG} = tail_close($fh);
|
| 92 |
$positions{'count'} = $positions{'count'} + $count;
|
| 93 |
} |
| 94 |
else {
|
| 95 |
$positions{$LOG} = (stat $LOG)[7];
|
| 96 |
$positions{'count'} = 0;
|
| 97 |
} |
| 98 |
|
| 99 |
print "hits.value $positions{'count'}\n";
|
| 100 |
if($positions{'count'} > 100000000) {
|
| 101 |
$positions{'count'} = 0;
|
| 102 |
} |
| 103 |
save_state(%positions); |
| 104 |
} |
