]> arthur.barton.de Git - netdata.git/blob - python.d/apache_cache.chart.py
Merge pull request #1952 from ktsaou/master
[netdata.git] / python.d / apache_cache.chart.py
1 # -*- coding: utf-8 -*-
2 # Description: apache cache netdata python.d module
3 # Author: Pawel Krupa (paulfantom)
4
5 from base import LogService
6
7 priority = 60000
8 retries = 60
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             ["other", None, "percentage-of-absolute-row"]
19         ]}
20 }
21
22
23 class Service(LogService):
24     def __init__(self, configuration=None, name=None):
25         LogService.__init__(self, configuration=configuration, name=name)
26         if len(self.log_path) == 0:
27             self.log_path = "/var/log/apache2/cache.log"
28         self.order = ORDER
29         self.definitions = CHARTS
30
31     def _get_data(self):
32         """
33         Parse new log lines
34         :return: dict
35         """
36         try:
37             raw = self._get_raw_data()
38             if raw is None:
39                 return None
40             elif not raw:
41                 return {'hit': 0,
42                         'miss': 0,
43                         'other': 0}
44         except (ValueError, AttributeError):
45             return None
46
47         hit = 0
48         miss = 0
49         other = 0
50         for line in raw:
51             if "cache hit" in line:
52                 hit += 1
53             elif "cache miss" in line:
54                 miss += 1
55             else:
56                 other += 1
57
58         return {'hit': hit,
59                 'miss': miss,
60                 'other': other}