]> arthur.barton.de Git - netdata.git/commitdiff
apache_cache python module
authorpaulfantom <paulfantom@gmail.com>
Fri, 1 Jul 2016 11:35:22 +0000 (13:35 +0200)
committerpaulfantom <paulfantom@gmail.com>
Fri, 1 Jul 2016 11:35:22 +0000 (13:35 +0200)
python.d/Makefile.am
python.d/apache_cache.chart.py [new file with mode: 0644]

index d96ead822b0ac4d40486495b3dd116355bc95af7..2d6d70c18d8d8f8c677bda3cf00ffba81592e6a9 100644 (file)
@@ -10,6 +10,7 @@ dist_python_SCRIPTS = \
        phpfpm.chart.py \
        apache.chart.py \
        nginx.chart.py \
+       apache_cache.chart.py \
        python-modules-installer.sh \
        $(NULL)
 
diff --git a/python.d/apache_cache.chart.py b/python.d/apache_cache.chart.py
new file mode 100644 (file)
index 0000000..2510cd4
--- /dev/null
@@ -0,0 +1,51 @@
+# -*- coding: utf-8 -*-
+# Description: apache cache netdata python.d plugin
+# Author: Pawel Krupa (paulfantom)
+
+from base import LogService
+
+priority = 60000
+retries = 5
+
+ORDER = ['cache']
+CHARTS = {
+    'cache': {
+        'options': [None, 'apache cached responses', 'percent cached', 'cached', 'apache_cache.cache', 'stacked'],
+        'lines': [
+            ["hit", 'cache', "percentage-of-absolute-row"],
+            ["miss", None, "percentage-of-absolute-row"]
+        ]}
+}
+
+
+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.order = ORDER
+        self.definitions = CHARTS
+
+    def _formatted_data(self):
+        """
+        Parse new log lines
+        :return: dict
+        """
+        try:
+            raw = self._get_data()
+        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:
+            return None
+
+        return {'hit': int(hit/float(hit+miss) * 100),
+                'miss': int(miss/float(hit+miss) * 100)}