]> arthur.barton.de Git - netdata.git/blob - python.d/apache_cache.chart.py
fixing issues after testing apache_cache.chart.py
[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 update_every = 3
10
11 ORDER = ['cache']
12 CHARTS = {
13     'cache': {
14         'options': [None, 'apache cached responses', 'percent cached', 'cached', 'apache_cache.cache', 'stacked'],
15         'lines': [
16             ["hit", 'cache', "percentage-of-absolute-row"],
17             ["miss", None, "percentage-of-absolute-row"]
18         ]}
19 }
20
21
22 class Service(LogService):
23     def __init__(self, configuration=None, name=None):
24         LogService.__init__(self, configuration=configuration, name=name)
25         if len(self.log_path) == 0:
26             self.log_path = "/var/log/apache2/cache.log"
27         self.order = ORDER
28         self.definitions = CHARTS
29
30     def _formatted_data(self):
31         """
32         Parse new log lines
33         :return: dict
34         """
35         try:
36             raw = self._get_data()
37             if raw is None:
38                 return None
39         except (ValueError, AttributeError):
40             return None
41
42         hit = 0
43         miss = 0
44
45         for line in raw:
46             if "cache hit" in line:
47                 hit += 1
48             elif "cache miss" in line:
49                 miss += 1
50
51         total = hit + miss
52         if total == 0:
53             return None
54
55         hit_percent = int(hit/float(total) * 100)
56         return {'hit': hit_percent,
57                 'miss': 100 - hit_percent}