]> arthur.barton.de Git - netdata.git/blob - python.d/apache_cache.chart.py
apache_cache python module
[netdata.git] / python.d / apache_cache.chart.py
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)}