From acc4135cd574cdca66cb2186a478b952aa115855 Mon Sep 17 00:00:00 2001 From: Charlie Allom Date: Tue, 17 Apr 2012 22:47:02 +0100 Subject: [PATCH 1/6] update to v1.1 --- plugins/network/mtr100_ | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/network/mtr100_ b/plugins/network/mtr100_ index 96cbb494..3fd59e79 100755 --- a/plugins/network/mtr100_ +++ b/plugins/network/mtr100_ @@ -7,6 +7,9 @@ # Author: tobias.geiger@vido.info # Please email me bugs/suggestions # +# Version: 1.1 +# Author: charlie@evilforbeginners.com +# changed: munin eats 1 character ds-names. prefix with "hop_" # # # HINT: Needs a bigger TIMEOUT-Value than the default (10) in /etc/munin/plugin-conf.d/munin-node , From fae716b47802d37fba6ccd888f59df1ae4e0d61a Mon Sep 17 00:00:00 2001 From: Charlie Allom Date: Tue, 17 Apr 2012 22:47:30 +0100 Subject: [PATCH 2/6] decrease pings to 5 for faster polling --- plugins/network/mtr100_ | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/network/mtr100_ b/plugins/network/mtr100_ index 3fd59e79..a6ccd626 100755 --- a/plugins/network/mtr100_ +++ b/plugins/network/mtr100_ @@ -50,7 +50,7 @@ fi dotrace() { -LC_ALL=C mtr -nrs 1024 -c 10 $totrace | grep -v "^HOST:" | LC_ALL=C awk -v C=$1 ' { +LC_ALL=C mtr -nrs 1024 -c 5 $totrace | grep -v "^HOST:" | LC_ALL=C awk -v C=$1 ' { label=$2 x=gsub("\\.","_",label) From 7c3ecf1bc5e40bf1855a867789c620852fc0a110 Mon Sep 17 00:00:00 2001 From: Charlie Allom Date: Tue, 17 Apr 2012 22:47:55 +0100 Subject: [PATCH 3/6] increase the ds-name to be prefixed by hop_ so newer munins wont try to store everything datapoint in "_" --- plugins/network/mtr100_ | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/network/mtr100_ b/plugins/network/mtr100_ index a6ccd626..ff40a9cb 100755 --- a/plugins/network/mtr100_ +++ b/plugins/network/mtr100_ @@ -65,9 +65,9 @@ total+=$6 END { for (x=1; x<=count; x++) { value=(val[x]/total)*100 - if ( C != "config" ) { printf "%s.value %2.2f\n",lab[x],value } - if ( C == "config" ) { print lab[x] ".label " name[x] } - if ( C == "config" ) { if ( x == 1 ) { print lab[x]".draw AREA" } else { print lab[x]".draw STACK" } } + if ( C != "config" ) { printf "%s.value %2.2f\n","hop_" lab[x],value } + if ( C == "config" ) { print "hop_" lab[x] ".label " name[x] } + if ( C == "config" ) { if ( x == 1 ) { print "hop_" lab[x]".draw AREA" } else { print "hop_" lab[x]".draw STACK" } } } }' } From 614c22dfe466c3e0e29ae34e5ecf60b57d31deda Mon Sep 17 00:00:00 2001 From: Danny Fullerton Date: Tue, 17 Apr 2012 17:49:02 -0400 Subject: [PATCH 4/6] Add ithe byprojects family (vhost AND regex monitoring) to apache and nginx. --- plugins/apache/apache_byprojects/README.md | 36 ++++++++ .../apache_byprojects/byprojects_access | 76 ++++++++++++++++ .../apache_byprojects/byprojects_bandwidth | 83 ++++++++++++++++++ .../byprojects_inout_bandwidth | 86 +++++++++++++++++++ plugins/nginx/nginx_byprojects/README.md | 36 ++++++++ .../nginx/nginx_byprojects/byprojects_access | 76 ++++++++++++++++ .../nginx_byprojects/byprojects_bandwidth | 84 ++++++++++++++++++ .../byprojects_inout_bandwidth | 86 +++++++++++++++++++ 8 files changed, 563 insertions(+) create mode 100644 plugins/apache/apache_byprojects/README.md create mode 100644 plugins/apache/apache_byprojects/byprojects_access create mode 100644 plugins/apache/apache_byprojects/byprojects_bandwidth create mode 100644 plugins/apache/apache_byprojects/byprojects_inout_bandwidth create mode 100644 plugins/nginx/nginx_byprojects/README.md create mode 100644 plugins/nginx/nginx_byprojects/byprojects_access create mode 100644 plugins/nginx/nginx_byprojects/byprojects_bandwidth create mode 100644 plugins/nginx/nginx_byprojects/byprojects_inout_bandwidth diff --git a/plugins/apache/apache_byprojects/README.md b/plugins/apache/apache_byprojects/README.md new file mode 100644 index 00000000..be89931c --- /dev/null +++ b/plugins/apache/apache_byprojects/README.md @@ -0,0 +1,36 @@ +# The 'byprojects' family +Those plugins are used to monitor different projects or vhost (i.e. either different log files or uing regular expression as filters) on the same web server. + +## munin_byprojects_access +Count the number of hits per projects/vhost. +![byproject_access](https://www.mantor.org/~northox/misc/munin-plugins/nginx_byprojects_access1-month.png "byproject_access") + +## munin_byprojects_bandwidth +Count the total bandwidth used by each projects/vhost. [Logtail] (https://www.fourmilab.ch/webtools/logtail/) is required. +![byproject_bandwidth](https://www.mantor.org/~northox/misc/munin-plugins/apache_byprojects_bandwidth-month.png "byproject_bandwidth") + +## munin_byprojects_inout_bandwidth +Counts the in/out bandwidth used by each projects/vhost. [Logtail] (https://www.fourmilab.ch/webtools/logtail/) is required. +![byproject_inout_bandwidth](https://www.mantor.org/~northox/misc/munin-plugins/apache_byprojects_inout_bandwidth-month.png "byproject_inout_bandwidth") + +## Installation +Installation is pretty straight forward. First you need to configure the plugin: + +Identify the file which will be used by logtail to identify it's position in the log and the path to logtail: + + $statepath = '/usr/local/var/munin/plugin-state'; # directory where logtail will save the state + $logtail = '/usr/local/bin/logtail'; + +Multiple logs can be used for the same project/vhost and a regular expression (regex) can be used as a filter: + + %logs = ( + 'prod' => ('/home/prod/log/access.log'), + 'test' => ( + ('/var/log/httpd/access.log', '"[A-Z]+ /test/'), + '/home/test/log/access.log' + ) + ); + +In the previous example the prod project graph will be using everything in /home/prod/log/access.log. The test project will be using eveything in /home/test/log/access.log and stuff that match '"[A-Z] /test/' in /var/log/httpd/access.log (e.g. "GET /test/). + +Then link the file just as any other plugins. diff --git a/plugins/apache/apache_byprojects/byprojects_access b/plugins/apache/apache_byprojects/byprojects_access new file mode 100644 index 00000000..6b5448ad --- /dev/null +++ b/plugins/apache/apache_byprojects/byprojects_access @@ -0,0 +1,76 @@ +#!/usr/bin/perl -w +# +# byprojects_access +# +# Perl script to monitor access *byprojects* (e.g. vhost) from multiple files and/or regex. +# +# Danny Fullerton +# Mantor Organization +# This work is licensed under a Creative Commons Attribution 3.0 Unported License. +# +# 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'), +# 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/' + +$server = 'Apache'; + +$statepath = '/usr/local/var/munin/plugin-state'; # where logtail will save the state +$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' + ) +); + +########### + +if(defined($ARGV[0])) { + if ($ARGV[0] eq 'autoconf') { + print "yes\n"; + exit(0); + } elsif ($ARGV[0] eq 'config') { + $order = ''; + while (($client, $files) = each(%logs)) { $order .= $client.' ' } + 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"; + } + 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 = $_; + if($buf eq '') { next } + if(!defined($regex) || $buf =~ m/$regex/) { + $i++; + } + } + close($lt); + $x++; + } + print $client.".value $i\n"; +} diff --git a/plugins/apache/apache_byprojects/byprojects_bandwidth b/plugins/apache/apache_byprojects/byprojects_bandwidth new file mode 100644 index 00000000..416ca666 --- /dev/null +++ b/plugins/apache/apache_byprojects/byprojects_bandwidth @@ -0,0 +1,83 @@ +#!/usr/bin/perl -w +# +# byprojects_bandwidth +# +# Perl script to monitor total bandwidth *byprojects* (e.g. vhost) from multiple files and/or regex. +# +# Danny Fullerton +# Mantor Organization +# +# You need logtail (https://www.fourmilab.ch/webtools/logtail/) and +# +# 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" +# where %I is input and %O is output. +# +# 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'), +# 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/' + +$statepath = '/usr/local/var/munin/plugin-state'; # directory where logtail will save the state +$logtail = '/usr/local/bin/logtail'; + +$server = 'Apache'; + +%logs = ( +'prod' => ('/home/prod/log/access.log'), +'test' => ( + ('/var/log/httpd/access.log', '"[A-Z]+ /test/'), + '/home/test/log/access.log' + ) +); + +########### + +if(defined($ARGV[0])) { + if ($ARGV[0] eq 'autoconf') { + print "yes\n"; + exit(0); + } elsif ($ARGV[0] eq 'config') { + $order = ''; + while (($client, $files) = each(%logs)) { $order .= $client.' ' } + print "graph_order $order\n"; + print "graph_title $server total bandwidth byprojects\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 various projects.\n"; + while (($client, $files) = each(%logs)) { + print $client.".label $client\n"; + print $client.".type GAUGE\n"; + } + exit(0); + } +} + +while (($client, $files) = each(%logs)) { + $i = $o = $x = 0; + foreach $file ($files) { + $regex = ''; + $state = $statepath.'/'.$client.$x.'_totalbandwidth.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 = $_; + if($buf eq '') { next } + if(!defined($regex) || $buf =~ m/$regex/) { + if($buf =~ m/(\d+) (\d+)$/) { + $i += $1; + $o += $2; + } + } + } + close($lt); + $x++; + } + $x = $i + $o; + print $client.".value $x\n"; +} + diff --git a/plugins/apache/apache_byprojects/byprojects_inout_bandwidth b/plugins/apache/apache_byprojects/byprojects_inout_bandwidth new file mode 100644 index 00000000..6a135988 --- /dev/null +++ b/plugins/apache/apache_byprojects/byprojects_inout_bandwidth @@ -0,0 +1,86 @@ +#!/usr/bin/perl -w +# +# byprojects_inout_bandwidth +# +# Perl script to monitor in/out bandwidth *byprojects* (e.g. vhost) from multiple files and/or regex. +# +# Danny Fullerton +# Mantor Organization +# +# You need logtail (https://www.fourmilab.ch/webtools/logtail/) and +# +# Apache: +# 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" +# where %I is input and %O is output. +# +# 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'), +# 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/' + +$server = 'Apache'; + +$statepath = '/usr/local/var/munin/plugin-state'; # directory where logtail will save the state +$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' + ) +); + +########### + +if(defined($ARGV[0])) { + if ($ARGV[0] eq 'autoconf') { + print "yes\n"; + exit(0); + } elsif ($ARGV[0] eq 'config') { + print "graph_title $server in/out bandwidth byprojects\n"; + print "graph_args --base 1000\n"; + print "graph_vlabel bits per \${graph_period} in (-) / out (+)\n"; + print "graph_category $server\n"; + print "graph_info This graph show $server in/out bandwidth used by various projects.\n"; + while (($client, $files) = each(%logs)) { + print "i".$client.".label $client\n"; + print "i".$client.".type GAUGE\n"; + print "i".$client.".graph no\n"; + print "i".$client.".cdef i".$client.",8,*\n"; + print "o".$client.".label $client\n"; + print "o".$client.".type GAUGE\n"; + print "o".$client.".negative i".$client."\n"; + print "o".$client.".cdef o".$client.",8,*\n"; + } + exit(0); + } +} + +while (($client, $files) = each(%logs)) { + $i = $o = $x = 0; + foreach $file ($files) { + $regex = ''; + $state = $statepath.'/'.$client.$x.'_inoutbandwidth.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 = $_; + if($buf eq '') { next } + if(!defined($regex) || $buf =~ m/$regex/) { + if($buf =~ m/(\d+) (\d+)$/) { + $i += $1; + $o += $2; + } + } + } + close($lt); + $x++; + } + print "i".$client.".value $i\n"; + print "o".$client.".value $o\n"; +} diff --git a/plugins/nginx/nginx_byprojects/README.md b/plugins/nginx/nginx_byprojects/README.md new file mode 100644 index 00000000..be89931c --- /dev/null +++ b/plugins/nginx/nginx_byprojects/README.md @@ -0,0 +1,36 @@ +# The 'byprojects' family +Those plugins are used to monitor different projects or vhost (i.e. either different log files or uing regular expression as filters) on the same web server. + +## munin_byprojects_access +Count the number of hits per projects/vhost. +![byproject_access](https://www.mantor.org/~northox/misc/munin-plugins/nginx_byprojects_access1-month.png "byproject_access") + +## munin_byprojects_bandwidth +Count the total bandwidth used by each projects/vhost. [Logtail] (https://www.fourmilab.ch/webtools/logtail/) is required. +![byproject_bandwidth](https://www.mantor.org/~northox/misc/munin-plugins/apache_byprojects_bandwidth-month.png "byproject_bandwidth") + +## munin_byprojects_inout_bandwidth +Counts the in/out bandwidth used by each projects/vhost. [Logtail] (https://www.fourmilab.ch/webtools/logtail/) is required. +![byproject_inout_bandwidth](https://www.mantor.org/~northox/misc/munin-plugins/apache_byprojects_inout_bandwidth-month.png "byproject_inout_bandwidth") + +## Installation +Installation is pretty straight forward. First you need to configure the plugin: + +Identify the file which will be used by logtail to identify it's position in the log and the path to logtail: + + $statepath = '/usr/local/var/munin/plugin-state'; # directory where logtail will save the state + $logtail = '/usr/local/bin/logtail'; + +Multiple logs can be used for the same project/vhost and a regular expression (regex) can be used as a filter: + + %logs = ( + 'prod' => ('/home/prod/log/access.log'), + 'test' => ( + ('/var/log/httpd/access.log', '"[A-Z]+ /test/'), + '/home/test/log/access.log' + ) + ); + +In the previous example the prod project graph will be using everything in /home/prod/log/access.log. The test project will be using eveything in /home/test/log/access.log and stuff that match '"[A-Z] /test/' in /var/log/httpd/access.log (e.g. "GET /test/). + +Then link the file just as any other plugins. diff --git a/plugins/nginx/nginx_byprojects/byprojects_access b/plugins/nginx/nginx_byprojects/byprojects_access new file mode 100644 index 00000000..4975cd0b --- /dev/null +++ b/plugins/nginx/nginx_byprojects/byprojects_access @@ -0,0 +1,76 @@ +#!/usr/bin/perl -w +# +# byprojects_access +# +# Perl script to monitor access *byprojects* (e.g. vhost) from multiple files and/or regex. +# +# Danny Fullerton +# Mantor Organization +# This work is licensed under a Creative Commons Attribution 3.0 Unported License. +# +# 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'), +# 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/' + +$server = 'Nginx'; + +$statepath = '/usr/local/var/munin/plugin-state'; # where logtail will save the state +$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' + ) +); + +########### + +if(defined($ARGV[0])) { + if ($ARGV[0] eq 'autoconf') { + print "yes\n"; + exit(0); + } elsif ($ARGV[0] eq 'config') { + $order = ''; + while (($client, $files) = each(%logs)) { $order .= $client.' ' } + 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"; + } + 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 = $_; + if($buf eq '') { next } + if(!defined($regex) || $buf =~ m/$regex/) { + $i++; + } + } + close($lt); + $x++; + } + print $client.".value $i\n"; +} diff --git a/plugins/nginx/nginx_byprojects/byprojects_bandwidth b/plugins/nginx/nginx_byprojects/byprojects_bandwidth new file mode 100644 index 00000000..39fa312b --- /dev/null +++ b/plugins/nginx/nginx_byprojects/byprojects_bandwidth @@ -0,0 +1,84 @@ +#!/usr/bin/perl -w +# +# byprojects_bandwidth +# +# Perl script to monitor total bandwidth *byprojects* (e.g. vhost) from multiple files and/or regex. +# +# Danny Fullerton +# Mantor Organization +# +# You need logtail (https://www.fourmilab.ch/webtools/logtail/) and +# +# 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" ' +# '$status $body_bytes_sent "$http_referer" ' +# '"$http_user_agent" $request_length $body_bytes_sent'; +# +# 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'), +# 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/' + +$statepath = '/usr/local/var/munin/plugin-state'; # directory where logtail will save the state +$logtail = '/usr/local/bin/logtail'; + +$server = 'Nginx'; + +%logs = ( +'prod' => ('/home/prod/log/access.log'), +'test' => ( + ('/var/log/httpd/access.log', '"[A-Z]+ /test/'), + '/home/test/log/access.log' + ) +); + +########### + +if(defined($ARGV[0])) { + if ($ARGV[0] eq 'autoconf') { + print "yes\n"; + exit(0); + } elsif ($ARGV[0] eq 'config') { + $order = ''; + while (($client, $files) = each(%logs)) { $order .= $client.' ' } + print "graph_order $order\n"; + print "graph_title $server total bandwidth byprojects\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 various projects.\n"; + while (($client, $files) = each(%logs)) { + print $client.".label $client\n"; + print $client.".type GAUGE\n"; + } + exit(0); + } +} + +while (($client, $files) = each(%logs)) { + $i = $o = $x = 0; + foreach $file ($files) { + $regex = ''; + $state = $statepath.'/'.$client.$x.'_totalbandwidth.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 = $_; + if($buf eq '') { next } + if(!defined($regex) || $buf =~ m/$regex/) { + if($buf =~ m/(\d+) (\d+)$/) { + $i += $1; + $o += $2; + } + } + } + close($lt); + $x++; + } + $x = $i + $o; + print $client.".value $x\n"; +} + diff --git a/plugins/nginx/nginx_byprojects/byprojects_inout_bandwidth b/plugins/nginx/nginx_byprojects/byprojects_inout_bandwidth new file mode 100644 index 00000000..de8c888e --- /dev/null +++ b/plugins/nginx/nginx_byprojects/byprojects_inout_bandwidth @@ -0,0 +1,86 @@ +#!/usr/bin/perl -w +# +# byprojects_inout_bandwidth +# +# Perl script to monitor in/out bandwidth *byprojects* (e.g. vhost) from multiple files and/or regex. +# +# Danny Fullerton +# Mantor Organization +# +# You need logtail (https://www.fourmilab.ch/webtools/logtail/) and +# +# 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" ' +# '$status $body_bytes_sent "$http_referer" ' +# '"$http_user_agent" $request_length $body_bytes_sent'; +# +# 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'), +# 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/' + +$server = 'Nginx'; + +$statepath = '/usr/local/var/munin/plugin-state'; # directory where logtail will save the state +$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' + ) +); + +########### + +if(defined($ARGV[0])) { + if ($ARGV[0] eq 'autoconf') { + print "yes\n"; + exit(0); + } elsif ($ARGV[0] eq 'config') { + print "graph_title $server in/out bandwidth byprojects\n"; + print "graph_args --base 1000\n"; + print "graph_vlabel bits per \${graph_period} in (-) / out (+)\n"; + print "graph_category $server\n"; + print "graph_info This graph show $server in/out bandwidth used by various projects.\n"; + while (($client, $files) = each(%logs)) { + print "i".$client.".label $client\n"; + print "i".$client.".type GAUGE\n"; + print "i".$client.".graph no\n"; + print "i".$client.".cdef i".$client.",8,*\n"; + print "o".$client.".label $client\n"; + print "o".$client.".type GAUGE\n"; + print "o".$client.".negative i".$client."\n"; + print "o".$client.".cdef o".$client.",8,*\n"; + } + exit(0); + } +} + +while (($client, $files) = each(%logs)) { + $i = $o = $x = 0; + foreach $file ($files) { + $regex = ''; + $state = $statepath.'/'.$client.$x.'_inoutbandwidth.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 = $_; + if($buf eq '') { next } + if(!defined($regex) || $buf =~ m/$regex/) { + if($buf =~ m/(\d+) (\d+)$/) { + $i += $1; + $o += $2; + } + } + } + close($lt); + $x++; + } + print "i".$client.".value $i\n"; + print "o".$client.".value $o\n"; +} From f15a674c84bffe59a81e1534030e0c88aba5c3d9 Mon Sep 17 00:00:00 2001 From: Alex Vasilenko Date: Wed, 18 Apr 2012 12:09:20 +0300 Subject: [PATCH 5/6] fixed php5 idle/active values --- plugins/nginx/php5-fpm_status | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/nginx/php5-fpm_status b/plugins/nginx/php5-fpm_status index 4b9396bd..c885225d 100755 --- a/plugins/nginx/php5-fpm_status +++ b/plugins/nginx/php5-fpm_status @@ -41,8 +41,8 @@ if [ "$1" = "config" ]; then exit 0 else awk ' - /^idle/ {print "active.value " $3} - /^active/{print "idle.value " $3} + /^idle/ {print "idle.value " $3} + /^active/{print "active.value " $3} /^total/ {print "total.value " $3} ' < $statusfile fi From 33670ad2b2690e59957664298d1b78514733cd66 Mon Sep 17 00:00:00 2001 From: Blauwbek Date: Thu, 19 Apr 2012 00:28:40 +0200 Subject: [PATCH 6/6] Created SABNZBd graph plugins voor Speed and Data left. --- plugins/sabnzbd/sabnzbd_dataleft | 68 ++++++++++++++++++++++++++++++++ plugins/sabnzbd/sabnzbd_speed | 68 ++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 plugins/sabnzbd/sabnzbd_dataleft create mode 100644 plugins/sabnzbd/sabnzbd_speed diff --git a/plugins/sabnzbd/sabnzbd_dataleft b/plugins/sabnzbd/sabnzbd_dataleft new file mode 100644 index 00000000..41bad9b8 --- /dev/null +++ b/plugins/sabnzbd/sabnzbd_dataleft @@ -0,0 +1,68 @@ +#!/usr/bin/perl +# +# Munin plugins for sabnzbd +# +# Copyright (C) 2012 - Blauwbek +# +# SABnzbd : http://sabnzbd.org/ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Requires: XML::Simple +# LWP::UserAgent +# +# Configuration example +# [sabnzbd*] +# env.host http://host:port/ +# env.api apikey +# + +use strict; +use XML::Simple; +use LWP::UserAgent; + +#defines +my $HOST = exists $ENV{'host'} ? $ENV{'host'} : "http://localhost:8080/"; +my $API = exists $ENV{'api'} ? $ENV{'api'} : ""; +my $URL = $HOST."/sabnzbd/api?mode=qstatus&output=xml&apikey=".$API; +my $sURL = sprintf $URL; + +#config output +if(defined $ARGV[0] && $ARGV[0] eq 'config') +{ + print <new; +$get->agent('Munin_GetXML_sabnzbd_left '); + +#get xml and xml->perl +my $req = $get->get($sURL); +my $vals = $req->content(); +my $xmlvals = $xml->XMLin($vals); + +#get/output vals +my $left = $xmlvals->{mbleft}; +$left =~ /(\d+)\./; +print "rem.value ".$1."\n"; \ No newline at end of file diff --git a/plugins/sabnzbd/sabnzbd_speed b/plugins/sabnzbd/sabnzbd_speed new file mode 100644 index 00000000..474e8def --- /dev/null +++ b/plugins/sabnzbd/sabnzbd_speed @@ -0,0 +1,68 @@ +#!/usr/bin/perl +# +# Munin plugins for sabnzbd +# +# Copyright (C) 2012 - Blauwbek +# +# SABnzbd : http://sabnzbd.org/ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Requires: XML::Simple +# LWP::UserAgent +# +# Configuration example +# [sabnzbd*] +# env.host http://host:port/ +# env.api apikey +# + +use strict; +use XML::Simple; +use LWP::UserAgent; + +#defines +my $HOST = exists $ENV{'host'} ? $ENV{'host'} : "http://localhost:8080/"; +my $API = exists $ENV{'api'} ? $ENV{'api'} : ""; +my $URL = $HOST."/sabnzbd/api?mode=qstatus&output=xml&apikey=".$API; +my $sURL = sprintf $URL; + +#config output +if(defined $ARGV[0] && $ARGV[0] eq 'config') +{ + print <new; +$get->agent('Munin_GetXML_sabnzbd_speed '); + +#get xml and xml->perl +my $req = $get->get($sURL); +my $vals = $req->content(); +my $xmlvals = $xml->XMLin($vals); + +#get/output vals +my $speed = $xmlvals->{kbpersec}; +$speed =~ /(\d+)\./; +print "speed.value ".$1."\n"; \ No newline at end of file