Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from urllib.parse import urlparse, urlencode
from urllib.request import urlopen, Request
from urllib.error import HTTPError
except ImportError:
from urlparse import urlparse
from urllib import urlencode
from urllib2 import urlopen, Request, HTTPError
import time
import plugins
import re
class Plugin(plugins.BasePlugin):
__name__ = 'httpd'
def run(self, config):
Apache/httpd status page metrics
prev_cache = {}
next_cache = dict()
next_cache['ts'] = time.time()
prev_cache = self.get_agent_cache() # Get absolute values from previous check
request = Request(config.get('httpd', 'status_page_url'))
data = urlopen(request).read().decode('utf-8')
except Exception as e:
return False
exp = re.compile('^([A-Za-z ]+):\s+(.+)$')
results = {}
def parse_score_board(sb):
ret = []
ret.append(('IdleWorkers', sb.count('_')))
ret.append(('ReadingWorkers', sb.count('R')))
ret.append(('WritingWorkers', sb.count('W')))
ret.append(('KeepaliveWorkers', sb.count('K')))
ret.append(('DnsWorkers', sb.count('D')))
ret.append(('ClosingWorkers', sb.count('C')))
ret.append(('LoggingWorkers', sb.count('L')))
ret.append(('FinishingWorkers', sb.count('G')))
ret.append(('CleanupWorkers', sb.count('I')))
return ret
for line in data.split('\n'):
if line:
m = exp.match(line)
if m:
k =
v =
# Ignore the following values
if k == 'IdleWorkers' or k == 'Server Built' or k == 'Server Built' \
or k == 'CurrentTime' or k == 'RestartTime' or k == 'ServerUptime' \
or k == 'CPULoad' or k == 'CPUUser' or k == 'CPUSystem' \
or k == 'CPUChildrenUser' or k == 'CPUChildrenSystem' \
or k == 'ReqPerSec':
if k == 'Total Accesses':
results['requests_per_second'] = self.absolute_to_per_second(k, int(v), prev_cache)
next_cache['Total Accesses'] = int(v)
if k == 'Scoreboard':
for sb_kv in parse_score_board(v):
results[sb_kv[0]] = sb_kv[1]
results[k] = v
return results
if __name__ == '__main__':