Search Exchange
Search All Sites
Nagios Live Webinars
Let our experts show you how Nagios can help your organization.Login
Directory Tree
check_apache2.sh
1.3
2009-09-09
- Nagios 2.x
- Nagios 3.x
247294
File | Description |
---|---|
check_apache2.sh | The plugin (v1.3) |
LICENSE | GNU GPLv2 License |
check_apache2.php | PNP template |
Meet The New Nagios Core Services Platform
Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.
Monitoring Made Magically Better
- Nagios Core on Overdrive
- Powerful Monitoring Dashboards
- Time-Saving Configuration Wizards
- Open Source Powered Monitoring On Steroids
- And So Much More!
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
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)
byfrayber, May 15, 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.
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.
bydaviduco, November 22, 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'=
(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'=
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.
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.
bydavidak, August 11, 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
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
bykalimsayyed809@gmail.com, July 9, 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
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
It works like a charm, only the pnp4nagios needs some little tweaking but if you're familiair with php it's piece of cake.
bylinuxtovishesh, July 30, 2012
This is very good plug-in . Gathering server status but pnp4 template not working . Any idea please
bygeuse, July 19, 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.
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.
byshawnbrito, November 1, 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..
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
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
#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
}
# 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
}