Apache

check_apache2.sh

Description:

sh compliant script to check Apache’s HTTP Server via mod_status and ps

Current Version

1.3

Last Release Date

2009-09-09

Compatible With

  • Nagios 2.x
  • Nagios 3.x

Owner


Project Files
Project Photos
Project Notes
Description: check_apache2.sh is a Nagios plugin to check the Apache's server status. It monitors requests per second, bytes per second/request, amount of busy/idle workers and its CPU load. Let me know when it's not working for you via Mail or in my blog and I'll solve the problem. Example call: ./check_apache2.sh -H localhost -P 80 -t 3 -b /usr/sbin -p /var/run -n apache2.pid -s status_page [-S] [-R] [-wr] 100 [-cr] 250 Options: -H|--hostname) Sets the hostname. Default is: localhost -P|--port) Sets the port. Default is: 80 -t|--timeout) Sets a timeout within the server's status page must've been accessed. Otherwise the check will go into an error state. Default is: 3 -b|--binary-path) Sets the path to the apache binary. Used for getting Apache's CPU load. Default is: /usr/sbin -p|--pid-path) Path to Apache's pid file. Default is: /var/run -n|--pid-name) Name of Apache's pid file. Default is: apache2.pid -s|--status-page) Defines the name of the status page. Default is: server-status -R|--remote-server) Disabled the pid check so that remote Apaches can be queried. Default is: off -S|--secure) Enables HTTPS (no certificate check though). Default is: off -wr|--warning-req) Sets a warning level for requests per second. Default is: off -cr|--critical-req) Sets a critical level for requests per second. Default is: off Changelog * 2009-09-09 (Version 1.3) * Released revised version of check_apache2.sh with many improvements (no temporary files anymore, cleaner script) * Added appropriate PNP template * 2009-05-14 (Version 1.2) * Small bugfix related to the exit codes * 2009-04-27 (Version 1.2) * Added possibility to check server-status via HTTPS (no verification of certificate though) * 2009-03-20 (Version 1.1) * Added options to set warning/critical thresholds for requests per second (fully optional as seen above in the description) * Moved servers uptime to the extended info option's perfdata output * 2009-03-16: * did some slight improvements to the get_processes and check_processes function. In the near future I'll change this so that the script looks after the pid file instead of doing ps ax|grep -c xyz
Reviews (11) Add a Review
Good plugin with some issues
by frayber, May 31, 2019

It works good if you make changes as suggested in other reviews. If you have errors like the ones which daviduco has, remember that ExtendedStatus has to be set to On. I have always cpu load to 0, I think because it works only on localhost.



Does not work
by daviduco, November 30, 2016

# ./check_apache2.sh -H localhost -n httpd2.pid (standard_in) 2: syntax error OK - Apache serves Requests per second with an average CPU utilization of 0%. Busy workers: , idle: | 'cpu_load'=0 'req_psec'= 'bytes_psec'= 'bytes_preq'= 'workers_busy'= 'workers_idle'= # ./check_apache2.sh -H localhost -n httpd2.pid -wr 100 -cr 250 (standard_in) 2: syntax error ./check_apache2.sh: line 277: [: too many arguments ./check_apache2.sh: line 281: [: -ge: unary operator expected OK - Apache serves Requests per second with an average CPU utilization of 0%. Busy workers: , idle: | 'cpu_load'=0 'req_psec'= 'bytes_psec'= 'bytes_preq'= 'workers_busy'= 'workers_idle'= # ./check_apache2.sh -H localhost -P 80 -t 3 -b /usr/sbin -p /var/run -n httpd2.pid -wr 100 -cr 250 (standard_in) 2: syntax error ./check_apache2.sh: line 277: [: too many arguments ./check_apache2.sh: line 281: [: -ge: unary operator expected OK - Apache serves Requests per second with an average CPU utilization of 0%. Busy workers: , idle: | 'cpu_load'=0 'req_psec'= 'bytes_psec'= 'bytes_preq'= 'workers_busy'= 'workers_idle'= # ./check_apache2.sh -H localhost -P 80 -t 3 -b /usr/sbin -p /var/run -n httpd2.pid (standard_in) 2: syntax error OK - Apache serves Requests per second with an average CPU utilization of 0%. Busy workers: , idle: | 'cpu_load'=0 'req_psec'= 'bytes_psec'= 'bytes_preq'= 'workers_busy'= 'workers_idle'=



Template problem
by friendyogi, October 31, 2014

Along with the Array definition problem which davidak has pointed out on Aug 11, 2014, I found a question mark (?) missing in the php template file. After adding this question mark in PHP tag the pnp4nagios graph are populated. Changes required in check_apache2.php:- 1. Remove dot (.) from $opt[2] and $def[2] lines as mentioned by Davidak 2. Add question mark (?) to the php open tag at the beginning of file.



template syntax error
by davidak, August 31, 2014

the template don't work. first it starts with "ine array indexes before adding content... change: $opt[2] .= "--vertical-label "Byte/sec " -l 0 -r --title "Apache metrics for $hostname / $servicedesc" "; $def[2] .= "DEF:bytepsec=$rrdfile:$DS[3]:AVERAGE " ; to: $opt[2] = "--vertical-label "Byte/sec " -l 0 -r --title "Apache metrics for $hostname / $servicedesc" "; $def[2] = "DEF:bytepsec=$rrdfile:$DS[3]:AVERAGE " ; please test code yourself before publishing it. except that the plugin works with Icinga 1.8.3



check_apache2.sh cpu load
by kalimsayyed809@gmail.com, July 31, 2013

Hi geuse, Just edit the name_pid="apache2.pid" to "httpd.pid" ./check_apache2.sh -H localhost -P 80 -t 3 -wr 100 -cr 250 OK - Apache serves 19 Requests per second with an average CPU utilization of 53.8%. Busy workers: 71, idle: 20 | 'cpu_load'=53.8 'req_psec'=19 'bytes_psec'=125950 'bytes_preq'=9918.87 'workers_busy'=71 'workers_idle'=20



Great
by Hermke, May 31, 2013

It works like a charm, only the pnp4nagios needs some little tweaking but if you're familiair with php it's piece of cake.



pnp4 template not working
by linuxtovishesh, July 31, 2012

This is very good plug-in . Gathering server status but pnp4 template not working . Any idea please



monitoring httpd problem...
by geuse, July 31, 2012

Does not work well with IBMHttpServer. little change to trap process httpd instead of Apache2: cpu_load="$(cpu_load=0; ps -Ao pcpu,args | grep "$path_binary/httpd" But does not work... ./check_apache2.sh -H ...myServer... -b /opt/IBMHttpServer/bin/ -n httpd.pid OK - Apache serves 35 Requests per second with an average CPU utilization of 0%. Busy workers: 5, idle: 70 | 'cpu_load'=0 'req_psec'=35 'bytes_psec'=756659 'bytes_preq'=11031.4 'workers_busy'=5 'workers_idle'=70 The variable cpu_load seems does not change.



Great Plugin To Get Apache Stats
by shawnbrito, November 30, 2011

This is an excellent plug-in to get the Apache Stats.. You may need to modify the pnp template a bit to get it operational as I'm having strict variable declaration in my PHP..



Template for PNP4Nagios
by seidler, September 30, 2011

Excellent script. Adding my contribution: A new template for PNP4Nagios, multigraph, with gradient colors and 4 graphs: 1) CPU Usage 2) Requests/Second 3) Bytes (per Second and per Request) 4) Workers (Idle and Busy) Works on PNP Version 0.6.14



check_apache.ncfg
by ecallaoc, April 30, 2011

#Nagios Grapher # Autor: Edward Callao Cortez (ecallaoc@hotmail.com define ngraph{ service_name APACHE graph_perf_regex cpu_load=(d+) graph_value cpu_load graph_units graph_legend CPU usage [%] rrd_plottype LINE2 rrd_color 008000 } define ngraph{ service_name APACHE type CDEF graph_value cpu_load_cdef graph_units graph_legend graph_calc cpu_load rrd_plottype LINE2 rrd_color 008000 } define ngraph{ service_name APACHE type GPRINT print_source cpu_load print_description Latest: print_function LAST print_format %2.2lf } define ngraph{ service_name APACHE type GPRINT print_source cpu_load print_description Maximum: print_function MAX print_format %2.2lf } define ngraph{ service_name APACHE type GPRINT print_source cpu_load print_description Average: print_function AVERAGE print_format %2.2lf print_eol left } define ngraph{ service_name APACHE graph_perf_regex req_psec=(d+) graph_value req_psec graph_units graph_legend Requests/sec rrd_plottype LINE2 rrd_color 0C64E8 } define ngraph{ service_name APACHE type CDEF graph_value req_psec_cdef graph_units graph_legend graph_calc req_psec rrd_plottype LINE2 rrd_color 0C64E8 } define ngraph{ service_name APACHE type GPRINT print_source req_psec print_description Latest: print_function LAST print_format %2.2lf } define ngraph{ service_name APACHE type GPRINT print_source req_psec print_description Maximum: print_function MAX print_format %2.2lf } define ngraph{ service_name APACHE type GPRINT print_source req_psec print_description Average: print_function AVERAGE print_format %2.2lf print_eol left } define ngraph{ service_name APACHE graph_perf_regex bytes_preq=(d+.d+) graph_value bytes_preq graph_legend Byte/req rrd_type DERIVE rrd_min 0 hide yes } define ngraph{ service_name APACHE type CDEF graph_value bytes_preq_cdef graph_units graph_legend Kb/req graph_calc bytes_preq,1024,/ rrd_plottype LINE2 rrd_color FFA500 } define ngraph{ service_name APACHE type GPRINT print_source bytes_preq_cdef print_description Latest: print_function LAST print_format %2.2lf } define ngraph{ service_name APACHE type GPRINT print_source bytes_preq_cdef print_description Maximum: print_function MAX print_format %2.2lf } define ngraph{ service_name APACHE type GPRINT print_source bytes_preq_cdef print_description Average: print_function AVERAGE print_format %2.2lf print_eol left } define ngraph{ service_name APACHE graph_perf_regex workers_busy=(d+) graph_value workers_busy graph_units graph_legend Busy workers rrd_plottype LINE2 rrd_color 1CC8E8 } define ngraph{ service_name APACHE type CDEF graph_value workers_busy_cdef graph_units graph_legend graph_calc workers_busy rrd_plottype LINE2 rrd_color 1CC8E8 } define ngraph{ service_name APACHE type GPRINT print_source workers_busy print_description Latest: print_function LAST print_format %2.2lf } define ngraph{ service_name APACHE type GPRINT print_source workers_busy print_description Maximum: print_function MAX print_format %2.2lf } define ngraph{ service_name APACHE type GPRINT print_source workers_busy print_description Average: print_function AVERAGE print_format %2.2lf print_eol left } define ngraph{ service_name APACHE graph_perf_regex workers_idle=(d+) graph_value workers_idle graph_units Various stats graph_legend Idle workers rrd_plottype LINE2 rrd_color E80C8C } define ngraph{ service_name APACHE type CDEF graph_value workers_idle_cdef graph_units graph_legend graph_calc workers_idle rrd_plottype LINE2 rrd_color E80C8C } define ngraph{ service_name APACHE type GPRINT print_source workers_idle print_description Latest: print_function LAST print_format %2.2lf } define ngraph{ service_name APACHE type GPRINT print_source workers_idle print_description Maximum: print_function MAX print_format %2.2lf } define ngraph{ service_name APACHE type GPRINT print_source workers_idle print_description Average: print_function AVERAGE print_format %2.2lf print_eol left }



Add a Review

You must be logged in to submit a review.

Thank you for your review!

Your review has been submitted and is pending approval.

Recommend

To:


From:


Thank you for your recommendation!

Your recommendation has been sent.

Project Stats
Rating
4.4 (13)
Favorites
4
Views
246,644