File: //usr/lib/python2.7/site-packages/lap/workers_apache_metric.py
import urllib2
import sys
import os
import yaml
os.environ["NO_PROXY"] = "localhost"
os.environ["no_proxy"] = "localhost"
def __run__(params):
try:
thresholds = yaml.load(params.get('thresholds'))
url = params.get("url", "http://localhost/server-status?auto")
except Exception, e:
return [1, "WARNING - 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['warning']:
return [1, "WARNING - %d (%.2f%%) busy apache workers (%d max)" % (busy, use, total), perfdata]
elif use > thresholds['critical']:
return [2, "CRITICAL - %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 [1, "WARNING - Error: %s" % repr(e)]