File: //proc/self/root/lib/python2.7/site-packages/lap/workers_apache.py
import urllib2
import sys
import os
import yaml
def __run__(params):
try:
thresholds = yaml.load(params.get('thresholds'))
noproxy = params.get("noproxy", False)
if noproxy:
urllib2.getproxies = lambda: {}
os.environ['no_proxy'] = '127.0.0.1,localhost'
url = params.get("url", "http://localhost/server-status?auto")
except Exception, e:
return [2, "CRITICAL - Error: %s" % repr(e)]
try:
busy = idle = free = 0
for line in [ line.split() for line in urllib2.urlopen(url).read().split("\n") if line ]:
if line[0] == "Scoreboard:":
idle = line[1].count("_")
free = line[1].count(".")
busy = len(line[1]) - (idle + free)
perfdata = []
perfdata.append(("workers_busy", str(busy)))
perfdata.append(("workers_idle", str(idle)))
perfdata.append(("workers_free", str(free)))
perfdata = "|".join([ "=".join(x) for x in perfdata])
total = busy + idle + free
use = (float(busy) / float(total)) * 100
if use > thresholds['critical']:
return [2, "CRITICAL - %d (%.2f%%) busy apache workers (%d max)" % (busy, use, total), perfdata]
elif use > thresholds['warning']:
return [1, "WARNING - %d (%.2f%%) busy apache workers (%d max)" % (busy, use, total), perfdata]
else:
return [0, "OK - %d (%.2f%%) busy apache workers (%d max)" % (busy, use, total), perfdata]
except Exception, e:
return [2, "CRITICAL - Error: %s" % repr(e)]