From 4771fd2b53abffaed26f1a86b135437994635a50 Mon Sep 17 00:00:00 2001 From: rfrail3 Date: Tue, 18 Sep 2012 19:15:56 +0200 Subject: [PATCH] New plugins for Apache web server --- plugins/apache/apache_average_requests | 128 +++++++++++++++++++++++++ plugins/apache/apache_memmory | 70 ++++++++++++++ plugins/apache/apache_servers | 65 +++++++++++++ plugins/apache/apache_threads | 89 +++++++++++++++++ plugins/apache/apache_tmemmory | 65 +++++++++++++ 5 files changed, 417 insertions(+) create mode 100755 plugins/apache/apache_average_requests create mode 100755 plugins/apache/apache_memmory create mode 100755 plugins/apache/apache_servers create mode 100755 plugins/apache/apache_threads create mode 100755 plugins/apache/apache_tmemmory diff --git a/plugins/apache/apache_average_requests b/plugins/apache/apache_average_requests new file mode 100755 index 00000000..e61eb6f9 --- /dev/null +++ b/plugins/apache/apache_average_requests @@ -0,0 +1,128 @@ +#!/usr/bin/perl +# -*- cperl -*- + +=head1 NAME + +apache_average_request - Munin plugin to monitor the average request to +Apache servers. It handles a list of ports passed in from a plugin +configuration file. + +=head1 APPLICABLE SYSTEMS + +Apache HTTP servers with C enabled. + +=head1 CONFIGURATION + +Enable stats in apache first!: + + + + SetHandler server-status + AuthUserFile /route/to/auth.file + AuthName Login-Stats + AuthType Basic + require valid-user + + + +And now in munin conf: + +[apache_*] +env.url http://USER:PASS@127.0.0.1/server-status?auto +env.ports 80 + +=head1 AUTHOR + +Ricardo Fraile +Unknown + +=head1 LICENSE + +GPLv2 + +=head1 MAGIC MARKERS + + #%# family=auto + #%# capabilities=autoconf + +=cut + +use strict; +use warnings; +use Munin::Plugin; + +my $ret = undef; + +if (! eval "require LWP::UserAgent;") +{ + $ret = "LWP::UserAgent not found"; + if ( ! defined $ARGV[0] ) { + die $ret; + } +} + +my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://127.0.0.1:%d/server-status?auto"; +my @PORTS = exists $ENV{'ports'} ? split(' ', $ENV{'ports'}) : (80); + +if ( defined $ARGV[0] and $ARGV[0] eq "autoconf" ) +{ + if ($ret) + { + print "no ($ret)\n"; + exit 0; + } + + my $ua = LWP::UserAgent->new(timeout => 30); + + foreach my $port (@PORTS) { + my $url = sprintf $URL, $port; + my $response = $ua->request(HTTP::Request->new('GET',$url)); + if ($response->is_success) { + if ($response->content =~ /^Total Accesses:/im ){ + next; + } + else { + print "no (ExtendedStatus option for apache" + . " mod_status is missing on port $port)\n"; + exit 0; + } + } + elsif ($response->code == 404) { + print "no (apache server-status not found. check if mod_status is enabled)\n"; + exit 0; + } + else { + print "no (Port $port: ". $response->message .")\n"; + exit 0; + } + } + print "yes\n"; + exit 0; +} + +if ( defined $ARGV[0] and $ARGV[0] eq "config" ) +{ + + print "graph_title Average apache request\n"; + print "graph_title Average apache Requests per second\n"; + print "graph_vlabel average reqs/sec\n"; + print "graph_scale no\n"; + print "graph_category apache\n"; + print "request.label Average apache reqs/sec\n"; + exit 0; + +} + +my $ua = LWP::UserAgent->new(timeout => 30); + +foreach my $port (@PORTS) { + my $url = sprintf $URL, $port; + my $response = $ua->request(HTTP::Request->new('GET',$url)); + if ($response->content =~ /^ReqPerSec:\s+(.+)$/im) { + print "request.value $1\n"; + } else { + print "request.value U\n"; + } +} + +# vim:syntax=perl diff --git a/plugins/apache/apache_memmory b/plugins/apache/apache_memmory new file mode 100755 index 00000000..30dd62bd --- /dev/null +++ b/plugins/apache/apache_memmory @@ -0,0 +1,70 @@ +#!/bin/sh +# -*- sh -*- + +: << =cut + +=head1 NAME + +apache_memmory -Indicate the medium size of all the apache child process + +=head1 CONFIGURATION + +[apache_*] +env.url http://USER:PASS@127.0.0.1/server-status?auto +env.apuser user_runnin_apache +env.binname apache_binary_name + + +=head1 AUTHOR + +Ricardo Fraile + +=head1 LICENSE + +GPLv2 + +=head1 MAGICK MARKERS + + #%# family=auto + #%# capabilities=autoconf + +=cut + +. $MUNIN_LIBDIR/plugins/plugin.sh + +USR=$apuser +PROCS=$binname + + +if [ "$1" = "autoconf" ]; then + echo yes + exit 0 +fi + +if [ "$1" = "config" ]; then + + echo 'graph_title Medium size of apache child process.' + echo 'graph_args --base 1000 -l 0 ' + echo 'graph_vlabel Kb' + echo 'graph_scale no' + echo 'graph_category apache' + echo 'graph_info Indicate the memdium size of all the apache child process.' + + + + echo "servers.label servers" + echo "servers.type GAUGE" + echo "servers.min 0" + + exit 0 +fi + +VAL1=`ps auxf | grep ${PROCS} | grep ${USR} | grep -v grep | wc -l` + +VAL2=`ps auxf | grep ${PROCS} | grep ${USR} | grep -v grep | awk '{s+=$6} END {print s}'` + +VAL3=`expr $VAL2 / $VAL1` + +echo "servers.value $VAL3" + + diff --git a/plugins/apache/apache_servers b/plugins/apache/apache_servers new file mode 100755 index 00000000..afedcfa8 --- /dev/null +++ b/plugins/apache/apache_servers @@ -0,0 +1,65 @@ +#!/bin/sh +# -*- sh -*- + +: << =cut + +=head1 NAME + +apache_servers -Indicate the number of apache servers running (child process) + +=head1 CONFIGURATION + +[apache_*] +env.url http://USER:PASS@127.0.0.1/server-status?auto +env.apuser user_runnin_apache +env.binname apache_binary_name + +=head1 AUTHOR + +Ricardo Fraile + +=head1 LICENSE + +GPLv2 + +=head1 MAGICK MARKERS + + #%# family=auto + #%# capabilities=autoconf + +=cut + +. $MUNIN_LIBDIR/plugins/plugin.sh + +USR=$apuser +PROCS=$binname + +if [ "$1" = "autoconf" ]; then + echo yes + exit 0 +fi + +if [ "$1" = "config" ]; then + + echo 'graph_title Number of apache servers running.' + echo 'graph_args --base 1000 -l 0 ' + echo 'graph_vlabel servers' + echo 'graph_scale no' + echo 'graph_category apache' + echo 'graph_info Indicate the number of apache servers running (child process).' + + + + echo "servers.label servers" + echo "servers.type GAUGE" + echo "servers.min 0" + echo "servers.info I/O on nfs" + + exit 0 +fi + +VAL1=`ps auxf | grep ${PROCS} | grep ${USR} | grep -v grep | wc -l` + +echo "servers.value $VAL1" + + diff --git a/plugins/apache/apache_threads b/plugins/apache/apache_threads new file mode 100755 index 00000000..5c0f0b02 --- /dev/null +++ b/plugins/apache/apache_threads @@ -0,0 +1,89 @@ +#!/bin/sh +# -*- sh -*- + +: << =cut + +=head1 NAME + +apache_threads -Indicate the memdium number of threads for all child process + +=head1 CONFIGURATION + +[apache_*] +env.url http://USER:PASS@127.0.0.1/server-status?auto +env.apuser user_runnin_apache +env.binname apache_binary_name + +=head1 AUTHOR + +Ricardo Fraile + +=head1 LICENSE + +GPLv2 + +=head1 MAGICK MARKERS + + #%# family=auto + #%# capabilities=autoconf + +=cut + +. $MUNIN_LIBDIR/plugins/plugin.sh + + +if [ "$1" = "autoconf" ]; then + echo yes + exit 0 +fi + +if [ "$1" = "config" ]; then + + echo 'graph_title Medium number of threads for child process.' + echo 'graph_args --base 1000 -l 0 ' + echo 'graph_vlabel Threads' + echo 'graph_scale no' + echo 'graph_category apache' + echo 'graph_info Indicate the memdium number of threads for all child process.' + + + + echo "threads.label threads" + echo "threads.type GAUGE" + echo "threads.min 0" + + exit 0 +fi + +SUM=0 +COUNT=0 +USR=$apuser +PROCS=$binname + + +# Catch proccess pid +VAL1=`ps auxf | grep ${PROCS} | grep ${USR} | grep -v grep | awk '{print $2}' ` + +# Count pids +COUNT=`ps auxf | grep ${PROCS} | grep ${USR} | grep -v grep | wc -l` + +# Read threads per pid +for i in $VAL1; do + + VAL2="$VAL2 `cat /proc/$i/status | grep 'Threads:' | awk '{print $2}'`" +done + +# Sun threads +for z in ${VAL2}; do + + SUM=`expr $SUM + $z` + +done + + +echo "threads.value `echo $((SUM / $COUNT))`" + + + + + diff --git a/plugins/apache/apache_tmemmory b/plugins/apache/apache_tmemmory new file mode 100755 index 00000000..6729ba75 --- /dev/null +++ b/plugins/apache/apache_tmemmory @@ -0,0 +1,65 @@ +#!/bin/sh +# -*- sh -*- + +: << =cut + +=head1 NAME + +apache_tmemmory -Indicate the total memory used by apache + +=head1 CONFIGURATION + +[apache_*] +env.url http://USER:PASS@127.0.0.1/server-status?auto +env.binname apache_binary_name + +=head1 AUTHOR + +Ricardo Fraile + +=head1 LICENSE + +GPLv2 + +=head1 MAGICK MARKERS + + #%# family=auto + #%# capabilities=autoconf + +=cut + +. $MUNIN_LIBDIR/plugins/plugin.sh + + +USR=$apuser +PROCS=$binname + + +if [ "$1" = "autoconf" ]; then + echo yes + exit 0 +fi + +if [ "$1" = "config" ]; then + + echo 'graph_title Total memory used by apache' + echo 'graph_args --base 1000 -l 0 ' + echo 'graph_vlabel Mb' + echo 'graph_scale no' + echo 'graph_category apache' + echo 'graph_info Indicate the total memory used by apache.' + + echo "servers.label servers" + echo "servers.type GAUGE" + echo "servers.min 0" + + exit 0 +fi + +VAL1=`ps auxf | grep ${PROCS} | grep -v grep | awk '{s+=$6} END {print s}'` + +VAL2=`expr $VAL1 / 1024` + +echo "servers.value $VAL2" + +