]> arthur.barton.de Git - netdata.git/commitdiff
fixing issues after testing apache_cache.chart.py
authorpaulfantom <paulfantom@gmail.com>
Fri, 1 Jul 2016 15:33:55 +0000 (17:33 +0200)
committerpaulfantom <paulfantom@gmail.com>
Fri, 1 Jul 2016 15:33:55 +0000 (17:33 +0200)
python.d/apache_cache.chart.py
python.d/python_modules/base.py

index 2510cd43000e7d1187b22fa5055bfb64f3eaf98a..16d056b97656a8129beb11edf607e8cef03b70b2 100644 (file)
@@ -6,6 +6,7 @@ from base import LogService
 
 priority = 60000
 retries = 5
+update_every = 3
 
 ORDER = ['cache']
 CHARTS = {
@@ -22,7 +23,7 @@ class Service(LogService):
     def __init__(self, configuration=None, name=None):
         LogService.__init__(self, configuration=configuration, name=name)
         if len(self.log_path) == 0:
-            self.log_path = "/var/log/httpd/cache.log"
+            self.log_path = "/var/log/apache2/cache.log"
         self.order = ORDER
         self.definitions = CHARTS
 
@@ -33,19 +34,24 @@ class Service(LogService):
         """
         try:
             raw = self._get_data()
+            if raw is None:
+                return None
         except (ValueError, AttributeError):
             return None
 
         hit = 0
         miss = 0
+
         for line in raw:
             if "cache hit" in line:
                 hit += 1
             elif "cache miss" in line:
                 miss += 1
 
-        if hit + miss == 0:
+        total = hit + miss
+        if total == 0:
             return None
 
-        return {'hit': int(hit/float(hit+miss) * 100),
-                'miss': int(miss/float(hit+miss) * 100)}
+        hit_percent = int(hit/float(total) * 100)
+        return {'hit': hit_percent,
+                'miss': 100 - hit_percent}
index 79e0438bc69b4058c105003c627b48c978249457..9562f7bac3d8de5d020620df327163df8fb90b59 100644 (file)
@@ -425,9 +425,13 @@ class LogService(SimpleService):
         #     'chart_name_in_netdata' : [ charts['chart_name_in_netdata']['lines']['name'] ]
         # }
         self.log_path = ""
-        self._last_line = 0
+        self._last_line = -1
         # self._log_reader = None
         SimpleService.__init__(self, configuration=configuration, name=name)
+        # FIXME Remove preventing of frequent log parsing
+        if self.timetable['freq'] < 3:
+            self.timetable['freq'] = 3
+        self.retries = 100000  # basically always retry
 
     def _get_data(self):
         # FIXME find faster solution of reading data. Maybe implement reading in subprocess?
@@ -436,7 +440,7 @@ class LogService(SimpleService):
         # if self._log_reader.poll() is not None:
         #    self._log_reader = Popen(['tail', '-F', self.log_path], stdout=PIPE, stderr=STDOUT)
         lines = []
-        last = 0
+        last = -1
         total = 0
         try:
             with open(self.log_path) as fp:
@@ -447,10 +451,10 @@ class LogService(SimpleService):
                     total += 1
         except Exception as e:
             msg.error(self.__module__, str(e))
-        if last != 0:
+        if last != -1:
             self._last_line = last
-        elif self._last_line > total:
-            self._last_line = 0
+        if self._last_line > total:
+            self._last_line = -1
 
         if len(lines) != 0:
             return lines
@@ -466,12 +470,14 @@ class LogService(SimpleService):
         except (KeyError, TypeError):
             self.error("No path to log specified. Using: '" + self.log_path + "'")
 
-        # FIXME Remove preventing of frequent log parsing
-        if self.update_every < 3:
-            self.update_every = 3
-
         if os.access(self.log_path, os.R_OK):
             return True
         else:
             self.error("Cannot access file: '" + self.log_path + "'")
             return False
+
+    def create(self):
+        status = SimpleService.create(self)
+        self._last_line = -1
+        return status
+