1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

Switch to strict mode.

Fix hash/array syntax causing regex-based log to fail.
This commit is contained in:
Danny Fullerton 2012-12-12 22:56:38 -05:00
parent c2ecfcb772
commit 5271859ff0
8 changed files with 300 additions and 233 deletions

View file

@ -1,4 +1,5 @@
#!/usr/bin/perl -w
use strict;
#
# byprojects_access
#
@ -10,25 +11,32 @@
#
# You need logtail (https://www.fourmilab.ch/webtools/logtail/)
#
# Log can be gather from multiple sources by simply specifying multiple log filename and/or an array with two
# elements: log filename and a regex.
# - 'prod' => array('/home/prod/log/access.log'),
# Log can be gathered from multiple sources by simply specifying multiple log filename
# and/or a log filename and a regex.
# - 'prod' => [ {'path' => '/home/prod/log/access.log'} ],
# Prod graph will be using everything in /home/prod/log/access.log
# - 'test' => array(array('/var/log/httpd/access.log', '"[A-Z]+ /test/'), '/home/test/log/access.log')
# Test graph will be using eveything in /home/test/log/access.log and stuff that match '"[A-Z] /test/' in
# /var/log/httpd/access.log such as '"GET /test/'
# - 'test' => [ {'path' => '/var/log/access.log', 'regex' => '"[A-Z]+ /test/'},
# {'path' => '/home/test/log/access.log'} ],
# Test graph will be using everything in /home/test/log/access.log and stuff that match
# '"[A-Z] /test/' in /var/log/access.log such as '"GET /test/'
$server = 'Apache';
my $server = 'Apache';
$statepath = '/usr/local/var/munin/plugin-state'; # where logtail will save the state
$logtail = '/usr/local/bin/logtail';
my $statepath = '/usr/local/var/munin/plugin-state'; # where logtail will save the state
my $logtail = '/usr/local/bin/logtail';
%logs = (
'prod' => ('/home/prod/log/access.log'),
'test' => (
('/var/log/httpd/access.log', '"[A-Z]+ /test/'),
'/home/test/log/access.log'
)
my %logs = (
'prod' => [
{'path' => '/home/prod/log/access.log'}
],
'dev' => [
{'path' => '/var/log/httpd/ssl-dev-access.log'},
{'path' => '/home/dev/log/access.log'}
],
'test' => [
{'path' => '/var/log/access.log', 'regex' => '"[A-Z]+ /test/'},
{'path' => '/home/test/log/access.log'}
],
);
###########
@ -38,39 +46,38 @@ if(defined($ARGV[0])) {
print "yes\n";
exit(0);
} elsif ($ARGV[0] eq 'config') {
$order = '';
while (($client, $files) = each(%logs)) { $order .= $client.' ' }
my $order = '';
while ((my $project, my @files) = each(%logs)) { $order .= $project.' ' }
print "graph_order $order\n";
print "graph_title $server access byprojects\n";
print "graph_total Total\n";
print "graph_vlabel Access by \${graph_period}\n";
print "graph_category $server\n";
print "graph_info This graph show $server access by various projects.\n";
while (($client, $files) = each(%logs)) {
print $client.".label $client\n";
print $client.".type DERIVE\n";
print $client.".min 0\n";
while ((my $project, my @files) = each(%logs)) {
print $project.".label $project";
print $project.".type DERIVE\n";
print $project.".min 0\n";
}
exit(0);
}
}
while (($client, $files) = each(%logs)) {
$x = $i = 0;
foreach $file ($files) {
$regex = '';
$state = $statepath.'/'.$client.$x.'_access.state';
if(ref($file) eq 'ARRAY') { ($file, $regex) = @file }
open(my $lt, "$logtail -f $file -o $state |") or die "Can't open $logtail : $!";
while (<$lt>) {
$buf = $_;
foreach my $project ( keys %logs ) {
my $i = 0;
my $x = 0;
foreach my $log ( @{$logs{$project}} ) {
my $state = $statepath.'/'.$project.$x.'_access.state';
open(LT, "$logtail -f ".$log->{'path'}." -o $state |") or die "Can't open $logtail : $!";
while (<LT>) {
my $buf = $_;
if($buf eq '') { next }
if(!defined($regex) || $buf =~ m/$regex/) {
if(!defined($log->{'regex'}) || $buf =~ m/$log->{'regex'}/) {
$i++;
}
}
close($lt);
close(LT);
$x++;
}
print $client.".value $i\n";
print $project.".value $i\n";
}