@cryptotaxi247 / netdata-1 / commits / 2f42d45be

apache_cache python module

paulfantom committed Jul 1, 2016 at 13:35 UTC 2f42d45beabbb4ec75e50201416d626a094fdd70
2 files changed +52
python.d/Makefile.am
+1
@@ -10,6 +10,7 @@ dist_python_SCRIPTS = \
10 phpfpm.chart.py \
11 apache.chart.py \
12 nginx.chart.py \
13 + apache_cache.chart.py \
14 python-modules-installer.sh \
15 $(NULL)
16
python.d/apache_cache.chart.py new
+51
@@ -0,0 +1,51 @@
1 +# -*- coding: utf-8 -*-
2 +# Description: apache cache netdata python.d plugin
3 +# Author: Pawel Krupa (paulfantom)
4 +
5 +from base import LogService
6 +
7 +priority = 60000
8 +retries = 5
9 +
10 +ORDER = ['cache']
11 +CHARTS = {
12 + 'cache': {
13 + 'options': [None, 'apache cached responses', 'percent cached', 'cached', 'apache_cache.cache', 'stacked'],
14 + 'lines': [
15 + ["hit", 'cache', "percentage-of-absolute-row"],
16 + ["miss", None, "percentage-of-absolute-row"]
17 + ]}
18 +}
19 +
20 +
21 +class Service(LogService):
22 + def __init__(self, configuration=None, name=None):
23 + LogService.__init__(self, configuration=configuration, name=name)
24 + if len(self.log_path) == 0:
25 + self.log_path = "/var/log/httpd/cache.log"
26 + self.order = ORDER
27 + self.definitions = CHARTS
28 +
29 + def _formatted_data(self):
30 + """
31 + Parse new log lines
32 + :return: dict
33 + """
34 + try:
35 + raw = self._get_data()
36 + except (ValueError, AttributeError):
37 + return None
38 +
39 + hit = 0
40 + miss = 0
41 + for line in raw:
42 + if "cache hit" in line:
43 + hit += 1
44 + elif "cache miss" in line:
45 + miss += 1
46 +
47 + if hit + miss == 0:
48 + return None
49 +
50 + return {'hit': int(hit/float(hit+miss) * 100),
51 + 'miss': int(miss/float(hit+miss) * 100)}