58 lines
1.6 KiB
Perl
58 lines
1.6 KiB
Perl
#!/usr/bin/perl -w
|
|
use strict;
|
|
|
|
# copied and modified from: https://github.com/munin-monitoring/contrib/tree/master/plugins/apache/apache_byprojects
|
|
|
|
my $server = 'Apache';
|
|
|
|
my $statepath = '/var/lib/munin/plugin-state';
|
|
my $logtail = '/usr/sbin/logtail';
|
|
|
|
my @logfiles = `ls /var/log/ispconfig/httpd/*/access.log`;
|
|
|
|
my $logs = {};
|
|
|
|
foreach (@logfiles) {
|
|
my $actFile = $_;
|
|
chomp($actFile);
|
|
(my $actLabel = $actFile) =~ s:.*/([^/]*)/access\.log:$1:;
|
|
(my $actId = $actLabel) =~ s/[^a-zA-Z0-9]/_/g;
|
|
$logs->{$actId}{'label'} = $actLabel;
|
|
$logs->{$actId}{'file'} = $actFile;
|
|
}
|
|
|
|
if(defined($ARGV[0])) {
|
|
if ($ARGV[0] eq 'autoconf') {
|
|
print "yes\n";
|
|
exit(0);
|
|
} elsif ($ARGV[0] eq 'config') {
|
|
print "graph_title $server accesses vhost\n";
|
|
# print "graph_total Total\n";
|
|
print "graph_vlabel accesses / \${graph_period}\n";
|
|
print "graph_category $server\n";
|
|
print "graph_args --base 1000\n";
|
|
print "graph_info This graph show $server access by vhost.\n";
|
|
my $draw = "AREA";
|
|
foreach my $vhostid (keys $logs) {
|
|
print $vhostid.".label $logs->{$vhostid}{'label'}\n";
|
|
print $vhostid.".draw $draw\n";
|
|
$draw = "STACK";
|
|
# print $vhostid.".type DERIVE\n";
|
|
# print $vhostid.".min 0\n";
|
|
}
|
|
exit(0);
|
|
}
|
|
}
|
|
|
|
foreach my $vhostid ( keys $logs ) {
|
|
my $i = 0;
|
|
my $state = $statepath.'/'.$vhostid.'_access.state';
|
|
open(LT, "$logtail -f ".$logs->{$vhostid}{'file'}." -o $state |") or die "Can't open $logtail : $!";
|
|
while (<LT>) {
|
|
my $buf = $_;
|
|
if($buf eq '') { next }
|
|
$i++;
|
|
}
|
|
close(LT);
|
|
print $vhostid.".value $i\n";
|
|
}
|