Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com

Login

Remember Me

Directory Tree

check_apache2.py

Rating
10 votes
Favoured:
0
Hits
105999
Files:
FileDescription
check_apache2.pyThe script (Version 1.0)
LICENSEThe appropriate license
Nagios CSP

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!
Script written in Python to check Apache2's server-status page with warning/critical threshold for req/sec
Description

check_apache2.py is a Python port of my sh compliant script check_apache2.sh, providing less features at the moment. It's main use for me is to get in touch with Python, but you might find it useful.
You're able to set a hostname, a port and to define warning/critical thresholds for requests per second. More features will be integrated within the next days when I find the time to do further work on the script.
Version

Version 1.0, 2009, Mike Adolphs (http://www.matejunkie.com/)
-h/--help Output

./check_apache2.py -h
Usage: check_apache2.py -H HOSTNAME -p PORT [-w] [-c]

Options:
--version show program's version number and exit
-h, --help show this help message and exit
-H HOSTNAME, --hostname=HOSTNAME
You may define a hostname with the -H option.
Default is: localhost.
-p PORT, --port=PORT
You may define a port with the -p option.
Default is: 80.

Warning/critical thresholds:
Use these options to set warning/critical thresholds
for requests per second served by your Apache.

-w WARNING, --warning=WARNING
Use this option if you want to use warning/critical

1. Make sure to set a critical value as
2. Default is: -1.

-c CRITICAL, --critical=CRITICAL
Use this option if you want to use warning/critical

1. Make sure to set a warning value as
2. Default is: -2.

Output example

user@host $ ./check_apache2.py --version
check_apache2.py 1.0
user@host $ ./check_apache2.py -H localhost -p 7001
OK: Apache serves 9.093710 requests per second. 1 busy workers, 49 idle workers.
user@host $ ./check_apache2.py -H localhost -p 7001 -w 2 -c 5
CRITICAL: Apache serves 9.082950 requests per second, exceeding critical threshold! 1 busy workers, 49 idle workers.
user@host $ ./check_apache2.py -H localhost -p 7001 -w 2 -c 10
WARNING: Apache serves 9.077650 requests per second, exceeding warning threshold! 1 busy workers, 49 idle workers.
user@host $ ./check_apache2.py -H localhost -p 7001 -w 10 -c 20
OK: Apache serves 9.073430 requests per second. 1 busy workers, 49 idle workers.
user@host $ ./check_apache2.py -H localhost -p 7001 -w 10 -c 5
UNKNOWN: When using thresholds the critical value has to be higher than the warning value. Please adjust your thresholds.
user@host $ ./check_apache2.py -H localhost -p 7001 -w 5
UNKNOWN: Please also set a critical value when using warning/critical thresholds!
user@host $ ./check_apache2.py -H localhost -p 7001 -c 5
UNKNOWN: Please also set a warning value when using warning/critical thresholds!
user@host $ ./check_apache2.py -H localhost -p 7002
CRITICAL: Couldn't fetch the server's status page. Please check given hostname, port or Apache's configuration. We might not be allowed to access server-status due to your server's configuration.
Changelog
Reviews (5)
byanordby, December 16, 2016
But did not really do what I wanted: check for minimum idle workers. I want to know they are not all busy. So I added an option to check that and extended this script. It is downloadable from my github repo for plugins: https://github.com/anordby/plugins/blob/master/nagios/check_apache2.py
Optimization: No tmp file needed
In retrieve_status_page() function change this: retrPage = urllib.urlretrieve(statusPage, '/tmp/server-status.log')
to this one: return urllib.urlopen(statusPage)

and modidy parse_status_page() function to parse_status_page(data):
# file = open('/tmp/server-status.log', 'r')
line = data.readline()
...
line = data.readline()

and finally in the main function add this line:
resParse = parse_status_page(retrieve_status_page())
so comment this lines:
#retrieve_status_page()
#resParse = parse_status_page()

Or you can see it:
https://gist.github.com/kajla/bf94e9c520f5cc706eb2e831af17129c
byMaquis196, January 23, 2014
Does exactly what it says on the tin, does a couple of things very well.

My only gripe would be that if a box doesn't allow the plugin to talk to the server-status page, it should give a nice error, not the Python traceback you get at the moment.

Otherwise, very very happy. Thanks for this.
SetHandler server-status
Order deny,allow
Deny from all
Allow from 127.0.0.1


ExtendedStatus On
byxoroz, February 8, 2011
0 of 2 people found this review helpful
I had this error:

Traceback (most recent call last):
File "./check_apache2.py", line 189, in ?
result = transform_dict(resParse)
File "./check_apache2.py", line 169, in transform_dict
totalAcc = int(resParse['totalAcc'].strip(" Total Accesses:"))
KeyError: 'totalAcc'