diff options
author | lookshe <github@lookshe.org> | 2015-02-03 15:53:16 +0100 |
---|---|---|
committer | lookshe <github@lookshe.org> | 2015-02-03 15:53:16 +0100 |
commit | 6a9971094a116d3d2fd636a4fa305214e4fa1f74 (patch) | |
tree | e64a3f979f2a778ee14e6d1cf614d7f529a7ca39 | |
parent | 6a4c7db21bb25c193d0faba891d3717762c1d2dd (diff) |
added munin script for vhost access and bandwith
-rw-r--r-- | vhost_access | 54 | ||||
-rw-r--r-- | vhost_bandwith | 55 |
2 files changed, 109 insertions, 0 deletions
diff --git a/vhost_access b/vhost_access new file mode 100644 index 0000000..cc45df0 --- /dev/null +++ b/vhost_access @@ -0,0 +1,54 @@ +#!/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 access vhost\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 vhost.\n"; + foreach my $vhostid (keys $logs) { + print $vhostid.".label $logs->{$vhostid}{'label'}\n"; + 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"; +} diff --git a/vhost_bandwith b/vhost_bandwith new file mode 100644 index 0000000..420ee0f --- /dev/null +++ b/vhost_bandwith @@ -0,0 +1,55 @@ +#!/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 total bandwidth vhost\n"; + print "graph_total Total\n"; + print "graph_vlabel Bits\n"; + print "graph_category $server\n"; + print "graph_info This graph show $server total bandwidth used by vhost.\n"; + foreach my $vhostid (keys $logs) { + print $vhostid.".label $logs->{$vhostid}{'label'}\n"; + print $vhostid.".type GAUGE\n"; + } + exit(0); + } +} + +foreach my $vhostid ( keys $logs ) { + my $i = 0; + my $state = $statepath.'/'.$vhostid.'_totalbandwidth.state'; + open(LT, "$logtail -f ".$logs->{$vhostid}{'file'}." -o $state |") or die "Can't open $logtail : $!"; + while (<LT>) { + my $buf = $_; + if($buf eq '') { next } + if($buf =~ m/" \d+ (\d+) "/) { + $i += $1; + } + } + close(LT); + print $vhostid.".value $i\n"; +} |