mirror of
https://github.com/munin-monitoring/contrib.git
synced 2018-11-08 00:59:34 +01:00
Merge pull request #407 from northox/glob_support
Add file expansion (glob) and switch to MIT license
This commit is contained in:
commit
760b07cdb6
@ -3,26 +3,30 @@ use strict;
|
|||||||
#
|
#
|
||||||
# byprojects_access
|
# byprojects_access
|
||||||
#
|
#
|
||||||
# Perl script to monitor access *byprojects* (e.g. vhost) from multiple files and/or regex.
|
# Perl script to monitor access *byprojects* (e.g. vhost) from multiple files
|
||||||
|
# and/or regex.
|
||||||
#
|
#
|
||||||
# Danny Fullerton <northox@mantor.org>
|
# Danny Fullerton <northox@mantor.org>
|
||||||
# Mantor Organization <www.mantor.org>
|
# Mantor Organization <www.mantor.org>
|
||||||
# This work is licensed under a Creative Commons Attribution 3.0 Unported License.
|
# This work is licensed under a MIT license.
|
||||||
#
|
#
|
||||||
# You need logtail (https://www.fourmilab.ch/webtools/logtail/)
|
# You need logtail (https://www.fourmilab.ch/webtools/logtail/)
|
||||||
#
|
#
|
||||||
# Log can be gathered from multiple sources by simply specifying multiple log filename
|
# Log can be gathered from multiple sources by simply specifying multiple log
|
||||||
# and/or a log filename and a regex.
|
# filename or using wildcards (glob). File content can be selected using regex.
|
||||||
# - 'prod' => [ {'path' => '/home/prod/log/access.log'} ],
|
#
|
||||||
# Prod graph will be using everything in /home/prod/log/access.log
|
# - 'prod' => [ {'path' => '/home/prod/log/access.log'} ],
|
||||||
# - 'test' => [ {'path' => '/var/log/access.log', 'regex' => '"[A-Z]+ /test/'},
|
# Prod graph will be using everything in /home/prod/log/access.log
|
||||||
# {'path' => '/home/test/log/access.log'} ],
|
#
|
||||||
# Test graph will be using everything in /home/test/log/access.log and stuff that match
|
# - 'test' => [ {'path' => '/var/log/access.log', 'regex' => '"[A-Z]+ /test/'},
|
||||||
# '"[A-Z] /test/' in /var/log/access.log such as '"GET /test/'
|
# {'path' => '/home/test/log/access*.log'} ],
|
||||||
|
# Test graph will be using everything file matching /home/test/log/access*.log
|
||||||
|
# and stuff that match the expression '"[A-Z] /test/' in /var/log/access.log
|
||||||
|
# such as '"GET /test/'
|
||||||
|
|
||||||
my $server = 'Apache';
|
my $server = 'Apache';
|
||||||
|
|
||||||
my $statepath = '/usr/local/var/munin/plugin-state'; # where logtail will save the state
|
my $statepath = '/usr/local/var/munin/plugin-state';
|
||||||
my $logtail = '/usr/local/bin/logtail';
|
my $logtail = '/usr/local/bin/logtail';
|
||||||
|
|
||||||
my %logs = (
|
my %logs = (
|
||||||
@ -67,17 +71,21 @@ foreach my $project ( keys %logs ) {
|
|||||||
my $i = 0;
|
my $i = 0;
|
||||||
my $x = 0;
|
my $x = 0;
|
||||||
foreach my $log ( @{$logs{$project}} ) {
|
foreach my $log ( @{$logs{$project}} ) {
|
||||||
my $state = $statepath.'/'.$project.$x.'_access.state';
|
my @paths = glob $log->{'path'};
|
||||||
open(LT, "$logtail -f ".$log->{'path'}." -o $state |") or die "Can't open $logtail : $!";
|
foreach my $path (@paths) {
|
||||||
while (<LT>) {
|
my $state = $statepath.'/'.$project.$x.'_access.state';
|
||||||
my $buf = $_;
|
open(LT, "$logtail -f ".$log->{'path'}." -o $state |") or
|
||||||
if($buf eq '') { next }
|
die "Can't open $logtail : $!";
|
||||||
if(!defined($log->{'regex'}) || $buf =~ m/$log->{'regex'}/) {
|
while (<LT>) {
|
||||||
$i++;
|
my $buf = $_;
|
||||||
|
if($buf eq '') { next }
|
||||||
|
if(!defined($log->{'regex'}) || $buf =~ m/$log->{'regex'}/) {
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
close(LT);
|
||||||
|
$x++;
|
||||||
}
|
}
|
||||||
close(LT);
|
|
||||||
$x++;
|
|
||||||
}
|
}
|
||||||
print $project.".value $i\n";
|
print $project.".value $i\n";
|
||||||
}
|
}
|
||||||
|
@ -3,30 +3,35 @@ use strict;
|
|||||||
#
|
#
|
||||||
# byprojects_bandwidth
|
# byprojects_bandwidth
|
||||||
#
|
#
|
||||||
# Perl script to monitor total bandwidth *byprojects* (e.g. vhost) from multiple files and/or regex.
|
# Perl script to monitor total bandwidth *byprojects* (e.g. vhost) from multiple
|
||||||
|
# files and/or regex.
|
||||||
#
|
#
|
||||||
# Danny Fullerton <northox@mantor.org>
|
# Danny Fullerton <northox@mantor.org>
|
||||||
# Mantor Organization <www.mantor.org>
|
# Mantor Organization <www.mantor.org>
|
||||||
# This work is licensed under a Creative Commons Attribution 3.0 Unported License.
|
# This work is licensed under a MIT license.
|
||||||
#
|
#
|
||||||
# You need logtail (https://www.fourmilab.ch/webtools/logtail/)
|
# You need logtail (https://www.fourmilab.ch/webtools/logtail/)
|
||||||
#
|
#
|
||||||
# mod_logio apache module (https://httpd.apache.org/docs/2.0/mod/mod_logio.html).
|
# mod_logio apache module (https://httpd.apache.org/docs/2.0/mod/mod_logio.html).
|
||||||
# Your logformat should look like this "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O"
|
# Your logformat should look like this:
|
||||||
|
# "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O"
|
||||||
# where %I is input and %O is output.
|
# where %I is input and %O is output.
|
||||||
#
|
#
|
||||||
# Log can be gathered from multiple sources by simply specifying multiple log filename
|
# Log can be gathered from multiple sources by simply specifying multiple log
|
||||||
# and/or a log filename and a regex.
|
# filename or using wildcards (glob). File content can be selected using regex.
|
||||||
# - 'prod' => [ {'path' => '/home/prod/log/access.log'} ],
|
#
|
||||||
# Prod graph will be using everything in /home/prod/log/access.log
|
# - 'prod' => [ {'path' => '/home/prod/log/access.log'} ],
|
||||||
# - 'test' => [ {'path' => '/var/log/access.log', 'regex' => '"[A-Z]+ /test/'},
|
# Prod graph will be using everything in /home/prod/log/access.log
|
||||||
# {'path' => '/home/test/log/access.log'} ],
|
#
|
||||||
# Test graph will be using everything in /home/test/log/access.log and stuff that match
|
# - 'test' => [ {'path' => '/var/log/access.log', 'regex' => '"[A-Z]+ /test/'},
|
||||||
# '"[A-Z] /test/' in /var/log/access.log such as '"GET /test/'
|
# {'path' => '/home/test/log/access*.log'} ],
|
||||||
|
# Test graph will be using everything file matching /home/test/log/access*.log
|
||||||
|
# and stuff that match the expression '"[A-Z] /test/' in /var/log/access.log
|
||||||
|
# such as '"GET /test/'
|
||||||
|
|
||||||
my $server = 'Apache';
|
my $server = 'Apache';
|
||||||
|
|
||||||
my $statepath = '/usr/local/var/munin/plugin-state'; # where logtail will save the state
|
my $statepath = '/usr/local/var/munin/plugin-state';
|
||||||
my $logtail = '/usr/local/bin/logtail';
|
my $logtail = '/usr/local/bin/logtail';
|
||||||
|
|
||||||
my %logs = (
|
my %logs = (
|
||||||
@ -58,7 +63,8 @@ if(defined($ARGV[0])) {
|
|||||||
print "graph_total Total\n";
|
print "graph_total Total\n";
|
||||||
print "graph_vlabel Bits\n";
|
print "graph_vlabel Bits\n";
|
||||||
print "graph_category $server\n";
|
print "graph_category $server\n";
|
||||||
print "graph_info This graph show $server total bandwidth used by various projects.\n";
|
print "graph_info This graph show $server total bandwidth used by various "\
|
||||||
|
"projects.\n";
|
||||||
while ((my $project, my @files) = each(%logs)) {
|
while ((my $project, my @files) = each(%logs)) {
|
||||||
print $project.".label $project\n";
|
print $project.".label $project\n";
|
||||||
print $project.".type GAUGE\n";
|
print $project.".type GAUGE\n";
|
||||||
@ -72,20 +78,24 @@ foreach my $project ( keys %logs ) {
|
|||||||
my $o = 0;
|
my $o = 0;
|
||||||
my $x = 0;
|
my $x = 0;
|
||||||
foreach my $log ( @{$logs{$project}} ) {
|
foreach my $log ( @{$logs{$project}} ) {
|
||||||
my $state = $statepath.'/'.$project.$x.'_totalbandwidth.state';
|
my @paths = glob $log->{'path'};
|
||||||
open(LT, "$logtail -f ".$log->{'path'}." -o $state |") or die "Can't open $logtail : $!";
|
foreach my $path (@paths) {
|
||||||
while (<LT>) {
|
my $state = $statepath.'/'.$project.$x.'_totalbandwidth.state';
|
||||||
my $buf = $_;
|
open(LT, "$logtail -f ".$log->{'path'}." -o $state |") or
|
||||||
if($buf eq '') { next }
|
die "Can't open $logtail : $!";
|
||||||
if(!defined($log->{'regex'}) || $buf =~ m/$log->{'regex'}/) {
|
while (<LT>) {
|
||||||
if($buf =~ m/(\d+) (\d+)$/) {
|
my $buf = $_;
|
||||||
$i += $1;
|
if($buf eq '') { next }
|
||||||
$o += $2;
|
if(!defined($log->{'regex'}) || $buf =~ m/$log->{'regex'}/) {
|
||||||
|
if($buf =~ m/(\d+) (\d+)$/) {
|
||||||
|
$i += $1;
|
||||||
|
$o += $2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
close(LT);
|
||||||
|
$x++;
|
||||||
}
|
}
|
||||||
close(LT);
|
|
||||||
$x++;
|
|
||||||
}
|
}
|
||||||
$x = $i + $o;
|
$x = $i + $o;
|
||||||
print $project.".value $x\n";
|
print $project.".value $x\n";
|
||||||
|
@ -3,30 +3,35 @@ use strict;
|
|||||||
#
|
#
|
||||||
# byprojects_inout_bandwidth
|
# byprojects_inout_bandwidth
|
||||||
#
|
#
|
||||||
# Perl script to monitor in/out bandwidth *byprojects* (e.g. vhost) from multiple files and/or regex.
|
# Perl script to monitor in/out bandwidth *byprojects* (e.g. vhost) from
|
||||||
|
# multiple files and/or regex.
|
||||||
#
|
#
|
||||||
# Danny Fullerton <northox@mantor.org>
|
# Danny Fullerton <northox@mantor.org>
|
||||||
# Mantor Organization <www.mantor.org>
|
# Mantor Organization <www.mantor.org>
|
||||||
# This work is licensed under a Creative Commons Attribution 3.0 Unported License.
|
# This work is licensed under a MIT license.
|
||||||
#
|
#
|
||||||
# You need logtail (https://www.fourmilab.ch/webtools/logtail/)
|
# You need logtail (https://www.fourmilab.ch/webtools/logtail/)
|
||||||
#
|
#
|
||||||
# mod_logio apache module (https://httpd.apache.org/docs/2.0/mod/mod_logio.html).
|
# mod_logio apache module (https://httpd.apache.org/docs/2.0/mod/mod_logio.html)
|
||||||
# Your logformat should look like this "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O"
|
# Your logformat should look like this:
|
||||||
|
# "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O"
|
||||||
# where %I is input and %O is output.
|
# where %I is input and %O is output.
|
||||||
#
|
#
|
||||||
# Log can be gathered from multiple sources by simply specifying multiple log filename
|
# Log can be gathered from multiple sources by simply specifying multiple log
|
||||||
# and/or a log filename and a regex.
|
# filename or using wildcards (glob). File content can be selected using regex.
|
||||||
# - 'prod' => [ {'path' => '/home/prod/log/access.log'} ],
|
#
|
||||||
# Prod graph will be using everything in /home/prod/log/access.log
|
# - 'prod' => [ {'path' => '/home/prod/log/access.log'} ],
|
||||||
# - 'test' => [ {'path' => '/var/log/access.log', 'regex' => '"[A-Z]+ /test/'},
|
# Prod graph will be using everything in /home/prod/log/access.log
|
||||||
# {'path' => '/home/test/log/access.log'} ],
|
#
|
||||||
# Test graph will be using everything in /home/test/log/access.log and stuff that match
|
# - 'test' => [ {'path' => '/var/log/access.log', 'regex' => '"[A-Z]+ /test/'},
|
||||||
# '"[A-Z] /test/' in /var/log/access.log such as '"GET /test/'
|
# {'path' => '/home/test/log/access*.log'} ],
|
||||||
|
# Test graph will be using everything file matching /home/test/log/access*.log
|
||||||
|
# and stuff that match the expression '"[A-Z] /test/' in /var/log/access.log
|
||||||
|
# such as '"GET /test/'
|
||||||
|
|
||||||
my $server = 'Apache';
|
my $server = 'Apache';
|
||||||
|
|
||||||
my $statepath = '/usr/local/var/munin/plugin-state'; # where logtail will save the state
|
my $statepath = '/usr/local/var/munin/plugin-state';
|
||||||
my $logtail = '/usr/local/bin/logtail';
|
my $logtail = '/usr/local/bin/logtail';
|
||||||
|
|
||||||
my %logs = (
|
my %logs = (
|
||||||
@ -55,7 +60,8 @@ if(defined($ARGV[0])) {
|
|||||||
print "graph_args --base 1000\n";
|
print "graph_args --base 1000\n";
|
||||||
print "graph_vlabel bits per \${graph_period} in (-) / out (+)\n";
|
print "graph_vlabel bits per \${graph_period} in (-) / out (+)\n";
|
||||||
print "graph_category $server\n";
|
print "graph_category $server\n";
|
||||||
print "graph_info This graph show $server in/out bandwidth used by various projects.\n";
|
print "graph_info This graph show $server in/out bandwidth used by various"\
|
||||||
|
" projects.\n";
|
||||||
while ((my $project, my @files) = each(%logs)) {
|
while ((my $project, my @files) = each(%logs)) {
|
||||||
print "i".$project.".label $project\n";
|
print "i".$project.".label $project\n";
|
||||||
print "i".$project.".type GAUGE\n";
|
print "i".$project.".type GAUGE\n";
|
||||||
@ -75,20 +81,24 @@ foreach my $project ( keys %logs ) {
|
|||||||
my $o = 0;
|
my $o = 0;
|
||||||
my $x = 0;
|
my $x = 0;
|
||||||
foreach my $log ( @{$logs{$project}} ) {
|
foreach my $log ( @{$logs{$project}} ) {
|
||||||
my $state = $statepath.'/'.$project.$x.'_inoutbandwidth.state';
|
my @paths = glob $log->{'path'};
|
||||||
open(LT, "$logtail -f ".$log->{'path'}." -o $state |") or die "Can't open $logtail : $!";
|
foreach my $path (@paths) {
|
||||||
while (<LT>) {
|
my $state = $statepath.'/'.$project.$x.'_inoutbandwidth.state';
|
||||||
my $buf = $_;
|
open(LT, "$logtail -f ".$log->{'path'}." -o $state |") or
|
||||||
if($buf eq '') { next }
|
die "Can't open $logtail : $!";
|
||||||
if(!defined($log->{'regex'}) || $buf =~ m/$log->{'regex'}/) {
|
while (<LT>) {
|
||||||
if($buf =~ m/(\d+) (\d+)$/) {
|
my $buf = $_;
|
||||||
$i += $1;
|
if($buf eq '') { next }
|
||||||
$o += $2;
|
if(!defined($log->{'regex'}) || $buf =~ m/$log->{'regex'}/) {
|
||||||
|
if($buf =~ m/(\d+) (\d+)$/) {
|
||||||
|
$i += $1;
|
||||||
|
$o += $2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
close(LT);
|
||||||
|
$x++;
|
||||||
}
|
}
|
||||||
close(LT);
|
|
||||||
$x++;
|
|
||||||
}
|
}
|
||||||
print "i".$project.".value $i\n";
|
print "i".$project.".value $i\n";
|
||||||
print "o".$project.".value $o\n";
|
print "o".$project.".value $o\n";
|
||||||
|
19
plugins/nginx/nginx_byprojects/LICENSE.txt
Normal file
19
plugins/nginx/nginx_byprojects/LICENSE.txt
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
Copyright (c) 2012-2013, Danny Fullerton, danny at mantor dot org
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
@ -29,7 +29,7 @@ Multiple logs can be used for the same project/vhost and a regular expression (r
|
|||||||
],
|
],
|
||||||
'dev' => [
|
'dev' => [
|
||||||
{'path' => '/var/log/httpd/ssl-dev-access.log'},
|
{'path' => '/var/log/httpd/ssl-dev-access.log'},
|
||||||
{'path' => '/home/dev/log/access.log'}
|
{'path' => '/home/dev/log/access*.log'} # glob is supported
|
||||||
],
|
],
|
||||||
'test' => [
|
'test' => [
|
||||||
{'path' => '/var/log/access.log', 'regex' => '"[A-Z]+ /test/'},
|
{'path' => '/var/log/access.log', 'regex' => '"[A-Z]+ /test/'},
|
||||||
@ -42,3 +42,6 @@ In the previous example the prod project graph will be using everything in /home
|
|||||||
Then link the file just as any other plugins.
|
Then link the file just as any other plugins.
|
||||||
|
|
||||||
ln -s /usr/local/sbin/<plugin> /usr/local/etc/munin/plugins/<plugin>
|
ln -s /usr/local/sbin/<plugin> /usr/local/etc/munin/plugins/<plugin>
|
||||||
|
|
||||||
|
## License
|
||||||
|
MIT
|
||||||
|
@ -3,26 +3,30 @@ use strict;
|
|||||||
#
|
#
|
||||||
# byprojects_access
|
# byprojects_access
|
||||||
#
|
#
|
||||||
# Perl script to monitor access *byprojects* (e.g. vhost) from multiple files and/or regex.
|
# Perl script to monitor access *byprojects* (e.g. vhost) from multiple files
|
||||||
|
# and/or regex.
|
||||||
#
|
#
|
||||||
# Danny Fullerton <northox@mantor.org>
|
# Danny Fullerton <northox@mantor.org>
|
||||||
# Mantor Organization <www.mantor.org>
|
# Mantor Organization <www.mantor.org>
|
||||||
# This work is licensed under a Creative Commons Attribution 3.0 Unported License.
|
# This work is licensed under a MIT license.
|
||||||
#
|
#
|
||||||
# You need logtail (https://www.fourmilab.ch/webtools/logtail/)
|
# You need logtail (https://www.fourmilab.ch/webtools/logtail/)
|
||||||
#
|
#
|
||||||
# Log can be gathered from multiple sources by simply specifying multiple log filename
|
# Log can be gathered from multiple sources by simply specifying multiple log
|
||||||
# and/or a log filename and a regex.
|
# filename or using wildcards (glob). File content can be selected using regex.
|
||||||
# - 'prod' => [ {'path' => '/home/prod/log/access.log'} ],
|
#
|
||||||
# Prod graph will be using everything in /home/prod/log/access.log
|
# - 'prod' => [ {'path' => '/home/prod/log/access.log'} ],
|
||||||
# - 'test' => [ {'path' => '/var/log/access.log', 'regex' => '"[A-Z]+ /test/'},
|
# Prod graph will be using everything in /home/prod/log/access.log
|
||||||
# {'path' => '/home/test/log/access.log'} ],
|
#
|
||||||
# Test graph will be using everything in /home/test/log/access.log and stuff that match
|
# - 'test' => [ {'path' => '/var/log/access.log', 'regex' => '"[A-Z]+ /test/'},
|
||||||
# '"[A-Z] /test/' in /var/log/access.log such as '"GET /test/'
|
# {'path' => '/home/test/log/access*.log'} ],
|
||||||
|
# Test graph will be using everything file matching /home/test/log/access*.log
|
||||||
|
# and stuff that match the expression '"[A-Z] /test/' in /var/log/access.log
|
||||||
|
# such as '"GET /test/'
|
||||||
|
|
||||||
my $server = 'Nginx';
|
my $server = 'Nginx';
|
||||||
|
|
||||||
my $statepath = '/usr/local/var/munin/plugin-state'; # where logtail will save the state
|
my $statepath = '/usr/local/var/munin/plugin-state';
|
||||||
my $logtail = '/usr/local/bin/logtail';
|
my $logtail = '/usr/local/bin/logtail';
|
||||||
|
|
||||||
my %logs = (
|
my %logs = (
|
||||||
@ -31,7 +35,7 @@ my %logs = (
|
|||||||
],
|
],
|
||||||
'dev' => [
|
'dev' => [
|
||||||
{'path' => '/var/log/httpd/ssl-dev-access.log'},
|
{'path' => '/var/log/httpd/ssl-dev-access.log'},
|
||||||
{'path' => '/home/dev/log/access.log'}
|
{'path' => '/home/dev/log/access*.log'} # glob is supported
|
||||||
],
|
],
|
||||||
'test' => [
|
'test' => [
|
||||||
{'path' => '/var/log/access.log', 'regex' => '"[A-Z]+ /test/'},
|
{'path' => '/var/log/access.log', 'regex' => '"[A-Z]+ /test/'},
|
||||||
@ -67,13 +71,17 @@ foreach my $project ( keys %logs ) {
|
|||||||
my $i = 0;
|
my $i = 0;
|
||||||
my $x = 0;
|
my $x = 0;
|
||||||
foreach my $log ( @{$logs{$project}} ) {
|
foreach my $log ( @{$logs{$project}} ) {
|
||||||
my $state = $statepath.'/'.$project.$x.'_access.state';
|
my @paths = glob $log->{'path'};
|
||||||
open(LT, "$logtail -f ".$log->{'path'}." -o $state |") or die "Can't open $logtail : $!";
|
foreach my $path (@paths) {
|
||||||
while (<LT>) {
|
my $state = $statepath.'/'.$project.$x.'_access.state';
|
||||||
my $buf = $_;
|
open(LT, "$logtail -f ".$log->{'path'}." -o $state |") or
|
||||||
if($buf eq '') { next }
|
die "Can't open $logtail: $!";
|
||||||
if(!defined($log->{'regex'}) || $buf =~ m/$log->{'regex'}/) {
|
while (<LT>) {
|
||||||
$i++;
|
my $buf = $_;
|
||||||
|
if($buf eq '') { next }
|
||||||
|
if(!defined($log->{'regex'}) || $buf =~ m/$log->{'regex'}/) {
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
close(LT);
|
close(LT);
|
||||||
|
@ -3,31 +3,36 @@ use strict;
|
|||||||
#
|
#
|
||||||
# byprojects_bandwidth
|
# byprojects_bandwidth
|
||||||
#
|
#
|
||||||
# Perl script to monitor total bandwidth *byprojects* (e.g. vhost) from multiple files and/or regex.
|
# Perl script to monitor total bandwidth *byprojects* (e.g. vhost) from multiple
|
||||||
|
# files and/or regex.
|
||||||
#
|
#
|
||||||
# Danny Fullerton <northox@mantor.org>
|
# Danny Fullerton <northox@mantor.org>
|
||||||
# Mantor Organization <www.mantor.org>
|
# Mantor Organization <www.mantor.org>
|
||||||
# This work is licensed under a Creative Commons Attribution 3.0 Unported License.
|
# This work is licensed under a MIT license.
|
||||||
#
|
#
|
||||||
# You need logtail (https://www.fourmilab.ch/webtools/logtail/)
|
# You need logtail (https://www.fourmilab.ch/webtools/logtail/)
|
||||||
#
|
#
|
||||||
# Your nginx configuration should look like this (i.e. $request_length $body_bytes_sent at the end):
|
# Your nginx configuration should look like this (i.e. $request_length
|
||||||
|
# body_bytes_sent at the end):
|
||||||
# log_format main '$remote_addr - $remote_user $time_local "$request" '
|
# log_format main '$remote_addr - $remote_user $time_local "$request" '
|
||||||
# '$status $body_bytes_sent "$http_referer" '
|
# '$status $body_bytes_sent "$http_referer" '
|
||||||
# '"$http_user_agent" $request_length $body_bytes_sent';
|
# '"$http_user_agent" $request_length $body_bytes_sent';
|
||||||
#
|
#
|
||||||
# Log can be gathered from multiple sources by simply specifying multiple log filename
|
# Log can be gathered from multiple sources by simply specifying multiple log
|
||||||
# and/or a log filename and a regex.
|
# filename or using wildcards (glob). File content can be selected using regex.
|
||||||
# - 'prod' => [ {'path' => '/home/prod/log/access.log'} ],
|
#
|
||||||
# Prod graph will be using everything in /home/prod/log/access.log
|
# - 'prod' => [ {'path' => '/home/prod/log/access.log'} ],
|
||||||
# - 'test' => [ {'path' => '/var/log/access.log', 'regex' => '"[A-Z]+ /test/'},
|
# Prod graph will be using everything in /home/prod/log/access.log
|
||||||
# {'path' => '/home/test/log/access.log'} ],
|
#
|
||||||
# Test graph will be using everything in /home/test/log/access.log and stuff that match
|
# - 'test' => [ {'path' => '/var/log/access.log', 'regex' => '"[A-Z]+ /test/'},
|
||||||
# '"[A-Z] /test/' in /var/log/access.log such as '"GET /test/'
|
# {'path' => '/home/test/log/access*.log'} ],
|
||||||
|
# Test graph will be using everything file matching /home/test/log/access*.log
|
||||||
|
# and stuff that match the expression '"[A-Z] /test/' in /var/log/access.log
|
||||||
|
# such as '"GET /test/'
|
||||||
|
|
||||||
my $server = 'Nginx';
|
my $server = 'Nginx';
|
||||||
|
|
||||||
my $statepath = '/usr/local/var/munin/plugin-state'; # where logtail will save the state
|
my $statepath = '/usr/local/var/munin/plugin-state';
|
||||||
my $logtail = '/usr/local/bin/logtail';
|
my $logtail = '/usr/local/bin/logtail';
|
||||||
|
|
||||||
my %logs = (
|
my %logs = (
|
||||||
@ -59,7 +64,8 @@ if(defined($ARGV[0])) {
|
|||||||
print "graph_total Total\n";
|
print "graph_total Total\n";
|
||||||
print "graph_vlabel Bits\n";
|
print "graph_vlabel Bits\n";
|
||||||
print "graph_category $server\n";
|
print "graph_category $server\n";
|
||||||
print "graph_info This graph show $server total bandwidth used by various projects.\n";
|
print "graph_info This graph show $server total bandwidth used by various "\
|
||||||
|
"projects.\n";
|
||||||
while ((my $project, my @files) = each(%logs)) {
|
while ((my $project, my @files) = each(%logs)) {
|
||||||
print $project.".label $project\n";
|
print $project.".label $project\n";
|
||||||
print $project.".type GAUGE\n";
|
print $project.".type GAUGE\n";
|
||||||
@ -73,20 +79,24 @@ foreach my $project ( keys %logs ) {
|
|||||||
my $o = 0;
|
my $o = 0;
|
||||||
my $x = 0;
|
my $x = 0;
|
||||||
foreach my $log ( @{$logs{$project}} ) {
|
foreach my $log ( @{$logs{$project}} ) {
|
||||||
my $state = $statepath.'/'.$project.$x.'_totalbandwidth.state';
|
my @paths = glob $log->{'path'};
|
||||||
open(LT, "$logtail -f ".$log->{'path'}." -o $state |") or die "Can't open $logtail : $!";
|
foreach my $path (@paths) {
|
||||||
while (<LT>) {
|
my $state = $statepath.'/'.$project.$x.'_totalbandwidth.state';
|
||||||
my $buf = $_;
|
open(LT, "$logtail -f ".$log->{'path'}." -o $state |") or
|
||||||
if($buf eq '') { next }
|
die "Can't open $logtail : $!";
|
||||||
if(!defined($log->{'regex'}) || $buf =~ m/$log->{'regex'}/) {
|
while (<LT>) {
|
||||||
if($buf =~ m/(\d+) (\d+)$/) {
|
my $buf = $_;
|
||||||
$i += $1;
|
if($buf eq '') { next }
|
||||||
$o += $2;
|
if(!defined($log->{'regex'}) || $buf =~ m/$log->{'regex'}/) {
|
||||||
|
if($buf =~ m/(\d+) (\d+)$/) {
|
||||||
|
$i += $1;
|
||||||
|
$o += $2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
close(LT);
|
||||||
|
$x++;
|
||||||
}
|
}
|
||||||
close(LT);
|
|
||||||
$x++;
|
|
||||||
}
|
}
|
||||||
$x = $i + $o;
|
$x = $i + $o;
|
||||||
print $project.".value $x\n";
|
print $project.".value $x\n";
|
||||||
|
@ -3,31 +3,36 @@ use strict;
|
|||||||
#
|
#
|
||||||
# byprojects_inout_bandwidth
|
# byprojects_inout_bandwidth
|
||||||
#
|
#
|
||||||
# Perl script to monitor in/out bandwidth *byprojects* (e.g. vhost) from multiple files and/or regex.
|
# Perl script to monitor in/out bandwidth *byprojects* (e.g. vhost) from
|
||||||
|
# multiple files and/or regex.
|
||||||
#
|
#
|
||||||
# Danny Fullerton <northox@mantor.org>
|
# Danny Fullerton <northox@mantor.org>
|
||||||
# Mantor Organization <www.mantor.org>
|
# Mantor Organization <www.mantor.org>
|
||||||
# This work is licensed under a Creative Commons Attribution 3.0 Unported License.
|
# This work is licensed under a MIT license.
|
||||||
#
|
#
|
||||||
# You need logtail (https://www.fourmilab.ch/webtools/logtail/)
|
# You need logtail (https://www.fourmilab.ch/webtools/logtail/)
|
||||||
#
|
#
|
||||||
# Your nginx configuration should look like this (i.e. $request_length $body_bytes_sent at the end):
|
# Your nginx configuration should look like this (i.e. $request_length
|
||||||
|
# body_bytes_sent at the end):
|
||||||
# log_format main '$remote_addr - $remote_user $time_local "$request" '
|
# log_format main '$remote_addr - $remote_user $time_local "$request" '
|
||||||
# '$status $body_bytes_sent "$http_referer" '
|
# '$status $body_bytes_sent "$http_referer" '
|
||||||
# '"$http_user_agent" $request_length $body_bytes_sent';
|
# '"$http_user_agent" $request_length $body_bytes_sent';
|
||||||
#
|
#
|
||||||
# Log can be gathered from multiple sources by simply specifying multiple log filename
|
# Log can be gathered from multiple sources by simply specifying multiple log
|
||||||
# and/or a log filename and a regex.
|
# filename or using wildcards (glob). File content can be selected using regex.
|
||||||
# - 'prod' => [ {'path' => '/home/prod/log/access.log'} ],
|
#
|
||||||
# Prod graph will be using everything in /home/prod/log/access.log
|
# - 'prod' => [ {'path' => '/home/prod/log/access.log'} ],
|
||||||
# - 'test' => [ {'path' => '/var/log/access.log', 'regex' => '"[A-Z]+ /test/'},
|
# Prod graph will be using everything in /home/prod/log/access.log
|
||||||
# {'path' => '/home/test/log/access.log'} ],
|
#
|
||||||
# Test graph will be using everything in /home/test/log/access.log and stuff that match
|
# - 'test' => [ {'path' => '/var/log/access.log', 'regex' => '"[A-Z]+ /test/'},
|
||||||
# '"[A-Z] /test/' in /var/log/access.log such as '"GET /test/'
|
# {'path' => '/home/test/log/access*.log'} ],
|
||||||
|
# Test graph will be using everything file matching /home/test/log/access*.log
|
||||||
|
# and stuff that match the expression '"[A-Z] /test/' in /var/log/access.log
|
||||||
|
# such as '"GET /test/'
|
||||||
|
|
||||||
my $server = 'Nginx';
|
my $server = 'Nginx';
|
||||||
|
|
||||||
my $statepath = '/usr/local/var/munin/plugin-state'; # where logtail will save the state
|
my $statepath = '/usr/local/var/munin/plugin-state';
|
||||||
my $logtail = '/usr/local/bin/logtail';
|
my $logtail = '/usr/local/bin/logtail';
|
||||||
|
|
||||||
my %logs = (
|
my %logs = (
|
||||||
@ -56,7 +61,8 @@ if(defined($ARGV[0])) {
|
|||||||
print "graph_args --base 1000\n";
|
print "graph_args --base 1000\n";
|
||||||
print "graph_vlabel bits per \${graph_period} in (-) / out (+)\n";
|
print "graph_vlabel bits per \${graph_period} in (-) / out (+)\n";
|
||||||
print "graph_category $server\n";
|
print "graph_category $server\n";
|
||||||
print "graph_info This graph show $server in/out bandwidth used by various projects.\n";
|
print "graph_info This graph show $server in/out bandwidth used by various"\
|
||||||
|
" projects.\n";
|
||||||
while ((my $project, my @files) = each(%logs)) {
|
while ((my $project, my @files) = each(%logs)) {
|
||||||
print "i".$project.".label $project\n";
|
print "i".$project.".label $project\n";
|
||||||
print "i".$project.".type GAUGE\n";
|
print "i".$project.".type GAUGE\n";
|
||||||
@ -76,20 +82,24 @@ foreach my $project ( keys %logs ) {
|
|||||||
my $o = 0;
|
my $o = 0;
|
||||||
my $x = 0;
|
my $x = 0;
|
||||||
foreach my $log ( @{$logs{$project}} ) {
|
foreach my $log ( @{$logs{$project}} ) {
|
||||||
my $state = $statepath.'/'.$project.$x.'_inoutbandwidth.state';
|
my @paths = glob $log->{'path'};
|
||||||
open(LT, "$logtail -f ".$log->{'path'}." -o $state |") or die "Can't open $logtail : $!";
|
foreach my $path (@paths) {
|
||||||
while (<LT>) {
|
my $state = $statepath.'/'.$project.$x.'_inoutbandwidth.state';
|
||||||
my $buf = $_;
|
open(LT, "$logtail -f ".$log->{'path'}." -o $state |") or
|
||||||
if($buf eq '') { next }
|
die "Can't open $logtail : $!";
|
||||||
if(!defined($log->{'regex'}) || $buf =~ m/$log->{'regex'}/) {
|
while (<LT>) {
|
||||||
if($buf =~ m/(\d+) (\d+)$/) {
|
my $buf = $_;
|
||||||
$i += $1;
|
if($buf eq '') { next }
|
||||||
$o += $2;
|
if(!defined($log->{'regex'}) || $buf =~ m/$log->{'regex'}/) {
|
||||||
|
if($buf =~ m/(\d+) (\d+)$/) {
|
||||||
|
$i += $1;
|
||||||
|
$o += $2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
close(LT);
|
||||||
|
$x++;
|
||||||
}
|
}
|
||||||
close(LT);
|
|
||||||
$x++;
|
|
||||||
}
|
}
|
||||||
print "i".$project.".value $i\n";
|
print "i".$project.".value $i\n";
|
||||||
print "o".$project.".value $o\n";
|
print "o".$project.".value $o\n";
|
||||||
|
Loading…
Reference in New Issue
Block a user