]> arthur.barton.de Git - netdata.git/blob - python.d/apache_cache.chart.py
prevent frequent opening of log files
[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         for line in raw:
45             if "cache hit" in line:
46                 hit += 1
47             elif "cache miss" in line:
48                 miss += 1
49
50         return {'hit': hit,
51                 'miss': miss}