This is a PNP template which works quite well for me when there’s need to identify possible bottlenecks or unexpected behavior of the Apache webserver. It shows the CPU usage, req/sec, byte/req and the amount of busy/idle workers in a single graph. Feel free to copy the template from below or head over to Nagios Exchange.
# 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 2 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, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # PNP Template for check_apache2.sh # Author: Mike Adolphs (http://www.matejunkie.com/) $opt[1] = "--vertical-label \"Various stats \" -l 0 -r --title \"Apache metrics for $hostname / $servicedesc\" "; $def[1] = "DEF:cpu=$rrdfile:$DS[1]:AVERAGE " ; $def[1] .= "DEF:reqpsec=$rrdfile:$DS[2]:AVERAGE " ; $def[1] .= "DEF:bytepreq=$rrdfile:$DS[4]:AVERAGE " ; $def[1] .= "DEF:wbusy=$rrdfile:$DS[5]:AVERAGE " ; $def[1] .= "DEF:widle=$rrdfile:$DS[6]:AVERAGE " ; $opt[2] .= "--vertical-label \"Byte/sec \" -l 0 -r --title \"Apache metrics for $hostname / $servicedesc\" "; $def[2] .= "DEF:bytepsec=$rrdfile:$DS[3]:AVERAGE " ; $def[1] .= "COMMENT:\"\\t\\t\\t\\tLAST\\t\\tAVERAGE\\t\\tMAX\\n\" " ; $def[1] .= "LINE2:cpu#008000:\"CPU usage [%]\\t \" " ; $def[1] .= "GPRINT:cpu:LAST:\"%6.0lf\\t\" " ; $def[1] .= "GPRINT:cpu:AVERAGE:\" %6.0lf\\t\" " ; $def[1] .= "GPRINT:cpu:MAX:\" %6.0lf\\n\" " ; $def[1] .= "LINE2:reqpsec#0C64E8:\"Requests/sec\\t \" " ; $def[1] .= "GPRINT:reqpsec:LAST:\"%6.0lf\\t\" " ; $def[1] .= "GPRINT:reqpsec:AVERAGE:\" %6.0lf\\t\" " ; $def[1] .= "GPRINT:reqpsec:MAX:\" %6.0lf\\n\" " ; $def[1] .= "LINE2:bytepreq#FFA500:\"Byte/req\\t\\t \" " ; $def[1] .= "GPRINT:bytepreq:LAST:\"%6.0lf\\t\" " ; $def[1] .= "GPRINT:bytepreq:AVERAGE:\" %6.0lf\\t\" " ; $def[1] .= "GPRINT:bytepreq:MAX:\" %6.0lf\\n\" " ; $def[1] .= "LINE2:wbusy#1CC8E8:\"Busy workers\\t \" " ; $def[1] .= "GPRINT:wbusy:LAST:\"%6.0lf\\t\" " ; $def[1] .= "GPRINT:wbusy:AVERAGE:\" %6.0lf\\t\" " ; $def[1] .= "GPRINT:wbusy:MAX:\" %6.0lf\\n\" " ; $def[1] .= "LINE2:widle#E80C8C:\"Idle workers\\t \" " ; $def[1] .= "GPRINT:widle:LAST:\"%6.0lf\\t\" " ; $def[1] .= "GPRINT:widle:AVERAGE:\" %6.0lf\\t\" " ; $def[1] .= "GPRINT:widle:MAX:\" %6.0lf\\n\" " ; $def[2] .= "COMMENT:\"\\t\\t\\t\\tLAST\\t\\tAVERAGE\\t\\tMAX\\n\" " ; $def[2] .= "LINE2:bytepsec#E80C3E:\"Byte/sec\\t\\t \" " ; $def[2] .= "GPRINT:bytepsec:LAST:\"%6.0lf\\t\" " ; $def[2] .= "GPRINT:bytepsec:AVERAGE:\" %6.0lf\\t\" " ; $def[2] .= "GPRINT:bytepsec:MAX:\" %6.0lf\\n\" " ;
First of all, thank you for a great PNP template and Apache check!
Just a heads up though, I found out that the check_apache2.php PNP template that was uploaded to the Nagios Exchange is a different version than posted here http://exchange.nagios.org/directory/Plugins/Web-Servers/Apache/check_apache2-2Esh/details
I noticed it when one had:
# PNP Template for check_bind.shand the blog post has the corrected:
# PNP Template for check_apache2.shAlso, a slight typo on the Nagios Exchange version:
Before
<phpAfter
<?phpThis had me stumped for a while when trying to get this template to work ;-)
Thanks again!
Heya Mike,
Quick question. I just updated to the PNP4Nagios 0.6.x version, and it seems like it doesn’t like your PHP template. It throws the error of “Template /usr/local/pnp4nagios/share/templates.dist/check_apache2.php does not provide array $def[].” Any ideas on what’s missing?
Thanks for all the work,
Dave
In response to Dave’s post, I had the same errors.
Changes:
1) Line 1 should be “<?php" not "<php"
2) Line 26, should start as "$opt[2] =" not "$opt[2] .="
3) Line 27, should start as "$def[2] =" not "$def[2] .="
That should fix it.