]> arthur.barton.de Git - netdata.git/commitdiff
Merge pull request #665 from paulfantom/master
authorCosta Tsaousis <costa@tsaousis.gr>
Thu, 7 Jul 2016 11:20:37 +0000 (14:20 +0300)
committerGitHub <noreply@github.com>
Thu, 7 Jul 2016 11:20:37 +0000 (14:20 +0300)
Cpufreq + exim + postfix

18 files changed:
conf.d/Makefile.am
conf.d/python.d/cpufreq.conf [new file with mode: 0644]
conf.d/python.d/exim.conf [new file with mode: 0644]
conf.d/python.d/postfix.conf [new file with mode: 0644]
python.d/Makefile.am
python.d/apache.chart.py
python.d/apache_cache.chart.py
python.d/cpufreq.chart.py [new file with mode: 0644]
python.d/example.chart.py
python.d/exim.chart.py [new file with mode: 0644]
python.d/hddtemp.chart.py
python.d/mysql.chart.py
python.d/nginx.chart.py
python.d/phpfpm.chart.py
python.d/postfix.chart.py [new file with mode: 0644]
python.d/python_modules/base.py
python.d/squid.chart.py
python.d/tomcat.chart.py

index faf4ecdfbc654b2b5871be6c05c4142e3d5906ee..ea19e0ab8014d56f489d84c6324c2f4596de0d76 100644 (file)
@@ -21,11 +21,14 @@ pythonconfigdir=$(configdir)/python.d
 dist_pythonconfig_DATA = \
        python.d/apache.conf \
        python.d/apache_cache.conf \
+       python.d/cpufreq.conf \
        python.d/example.conf \
+       python.d/exim.conf \
        python.d/hddtemp.conf \
        python.d/mysql.conf \
        python.d/nginx.conf \
        python.d/phpfpm.conf \
+       python.d/postfix.conf \
        python.d/squid.conf \
        python.d/tomcat.conf \
        $(NULL)
diff --git a/conf.d/python.d/cpufreq.conf b/conf.d/python.d/cpufreq.conf
new file mode 100644 (file)
index 0000000..e25910e
--- /dev/null
@@ -0,0 +1,4 @@
+# Example configuration of cpufreq.chart.py
+# YAML format
+
+update_every : 2
diff --git a/conf.d/python.d/exim.conf b/conf.d/python.d/exim.conf
new file mode 100644 (file)
index 0000000..2c13179
--- /dev/null
@@ -0,0 +1,4 @@
+# Example configuration of exim.chart.py
+# YAML format
+
+update_every : 2
diff --git a/conf.d/python.d/postfix.conf b/conf.d/python.d/postfix.conf
new file mode 100644 (file)
index 0000000..7612994
--- /dev/null
@@ -0,0 +1,4 @@
+# Example configuration of postfix.chart.py
+# YAML format
+
+update_every : 2
index 7f14bffa0ea840246992f483f8d0af171f9c7cc3..132e551be81b4a0c29339867fc75f44ad5d8b7fd 100644 (file)
@@ -8,13 +8,16 @@ include $(top_srcdir)/build/subst.inc
 SUFFIXES = .in
 
 dist_python_SCRIPTS = \
-       example.chart.py \
-       mysql.chart.py \
-       phpfpm.chart.py \
        apache.chart.py \
-       nginx.chart.py \
        apache_cache.chart.py \
+       cpufreq.chart.py \
+       example.chart.py \
+       exim.chart.py \
        hddtemp.chart.py \
+       mysql.chart.py \
+       nginx.chart.py \
+       phpfpm.chart.py \
+       postfix.chart.py \
        squid.chart.py \
        tomcat.chart.py \
        python-modules-installer.sh \
index f0f4fe2e13c53db0d2d0fdae85e07a7eae720e2a..b8ce614f1a3f7ac658d94428bf410f6af6984024 100644 (file)
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-# Description: apache netdata python.d plugin
+# Description: apache netdata python.d module
 # Author: Pawel Krupa (paulfantom)
 
 from base import UrlService
index 026d612da539495caf838ba45382fccc02a2bd0d..85b0ee170ee089608f43af513a273acde0596367 100644 (file)
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-# Description: apache cache netdata python.d plugin
+# Description: apache cache netdata python.d module
 # Author: Pawel Krupa (paulfantom)
 
 from base import LogService
diff --git a/python.d/cpufreq.chart.py b/python.d/cpufreq.chart.py
new file mode 100644 (file)
index 0000000..8677de5
--- /dev/null
@@ -0,0 +1,75 @@
+# -*- coding: utf-8 -*-
+# Description: cpufreq netdata python.d module
+# Author: Pawel Krupa (paulfantom)
+
+import os
+from base import SimpleService
+
+# default module values (can be overridden per job in `config`)
+# update_every = 2
+
+ORDER = ['cpufreq']
+
+CHARTS = {
+    'cpufreq': {
+        'options': [None, 'CPU Clock', 'MHz', 'cpufreq', None, 'line'],
+        'lines': [
+            # lines are created dynamically in `check()` method
+        ]}
+}
+
+
+class Service(SimpleService):
+    def __init__(self, configuration=None, name=None):
+        self.sys_dir = "/sys/devices"
+        self.filename = "scaling_cur_freq"
+        SimpleService.__init__(self, configuration=configuration, name=name)
+        self.order = ORDER
+        self.definitions = CHARTS
+        self._orig_name = ""
+        self.assignment = {}
+        self.paths = []
+
+    def _get_data(self):
+        raw = {}
+        for path in self.paths:
+            with open(path, 'r') as f:
+                raw[path] = f.read()
+        data = {}
+        for path in self.paths:
+            data[self.assignment[path]] = raw[path]
+        return data
+
+    def check(self):
+        self._orig_name = self.chart_name
+
+        for dirpath, _, filenames in os.walk(self.sys_dir):
+            if self.filename in filenames:
+                self.paths.append(dirpath + "/" + self.filename)
+
+        if len(self.paths) == 0:
+            return False
+
+        self.paths.sort()
+        i = 0
+        for path in self.paths:
+            self.assignment[path] = "cpu" + str(i)
+            i += 1
+
+        for name in self.assignment:
+            dim = self.assignment[name]
+            self.definitions[ORDER[0]]['lines'].append([dim, dim, 'absolute', 1, 1000])
+
+        return True
+
+    def create(self):
+        self.chart_name = "cpu"
+        status = SimpleService.create(self)
+        self.chart_name = self._orig_name
+        return status
+
+    def update(self, interval):
+        self.chart_name = "cpu"
+        status = SimpleService.update(self, interval=interval)
+        self.chart_name = self._orig_name
+        return status
index bc1846b76daf90f00feae715d04d16b985a1feaa..3d5cf8e0289c21185b2444ac887bbc0cb3024c47 100644 (file)
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-# Description: example netdata python.d plugin
+# Description: example netdata python.d module
 # Author: Pawel Krupa (paulfantom)
 
 import os
diff --git a/python.d/exim.chart.py b/python.d/exim.chart.py
new file mode 100644 (file)
index 0000000..a267c23
--- /dev/null
@@ -0,0 +1,41 @@
+# -*- coding: utf-8 -*-
+# Description: exim netdata python.d module
+# Author: Pawel Krupa (paulfantom)
+
+from base import ExecutableService
+
+# default module values (can be overridden per job in `config`)
+# update_every = 2
+priority = 60000
+retries = 5
+
+# charts order (can be overridden if you want less charts, or different order)
+ORDER = ['qemails']
+
+CHARTS = {
+    'qemails': {
+        'options': [None, "Exim Queue Emails", "emails", 'queue', 'exim.queued.emails', 'line'],
+        'lines': [
+            ['emails', None, 'absolute']
+        ]}
+}
+
+
+class Service(ExecutableService):
+    def __init__(self, configuration=None, name=None):
+        ExecutableService.__init__(self, configuration=configuration, name=name)
+        self.command = "exim -bpc"
+        self.order = ORDER
+        self.definitions = CHARTS
+
+    def _get_data(self):
+        """
+        Format data received from shell command
+        :return: dict
+        """
+        try:
+            raw = self._get_raw_data()[-1].split(' ')
+            return {'emails': raw[4],
+                    'size': raw[1]}
+        except (ValueError, AttributeError):
+            return None
index 2a549e7312f26f1139c03ea63d8110121a027e93..fac2ec6a167c93862d636922a732645cbdb6b79c 100644 (file)
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-# Description: hddtemp netdata python.d plugin
+# Description: hddtemp netdata python.d module
 # Author: Pawel Krupa (paulfantom)
 
 from base import NetSocketService
index 951daf2d2321db046cb1d0d9c56cc648c5f435f7..31bfbfbe948cf3a63ae1f266125ee4627921a88a 100644 (file)
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-# Description: MySQL netdata python.d plugin
+# Description: MySQL netdata python.d module
 # Author: Pawel Krupa (paulfantom)
 
 from base import SimpleService
index c50d0b72c675990e16c054e9980ac4f0111f71bd..8b7aab79227cbd648b4f1dba6a1e93d91e2267ed 100644 (file)
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-# Description: nginx netdata python.d plugin
+# Description: nginx netdata python.d module
 # Author: Pawel Krupa (paulfantom)
 
 from base import UrlService
index 024e6f5c7383afda668a15629708fa302b77efaa..5e5801103963afb1310c2a07795a1cbd2e411646 100755 (executable)
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-# Description: PHP-FPM netdata python.d plugin
+# Description: PHP-FPM netdata python.d module
 # Author: Pawel Krupa (paulfantom)
 
 from base import UrlService
diff --git a/python.d/postfix.chart.py b/python.d/postfix.chart.py
new file mode 100644 (file)
index 0000000..3f82715
--- /dev/null
@@ -0,0 +1,46 @@
+# -*- coding: utf-8 -*-
+# Description: postfix netdata python.d module
+# Author: Pawel Krupa (paulfantom)
+
+from base import ExecutableService
+
+# default module values (can be overridden per job in `config`)
+# update_every = 2
+priority = 60000
+retries = 5
+
+# charts order (can be overridden if you want less charts, or different order)
+ORDER = ['qemails', 'qsize']
+
+CHARTS = {
+    'qemails': {
+        'options': [None, "Postfix Queue Emails", "emails", 'queue', 'postfix.queued.emails', 'line'],
+        'lines': [
+            ['emails', None, 'absolute']
+        ]},
+    'qsize': {
+        'options': [None, "Postfix Queue Emails Size", "emails size in KB", 'queue', 'postfix.queued.size', 'area'],
+        'lines': [
+            ["size", None, 'absolute']
+        ]}
+}
+
+
+class Service(ExecutableService):
+    def __init__(self, configuration=None, name=None):
+        ExecutableService.__init__(self, configuration=configuration, name=name)
+        self.command = "postqueue -p"
+        self.order = ORDER
+        self.definitions = CHARTS
+
+    def _get_data(self):
+        """
+        Format data received from shell command
+        :return: dict
+        """
+        try:
+            raw = self._get_raw_data()[-1].split(' ')
+            return {'emails': raw[4],
+                    'size': raw[1]}
+        except (ValueError, AttributeError):
+            return None
index 6ec862834db9e186a2cb0adcc8527b85328d110e..c2d5793801119c38d4d0eb0b0ae6c2b055f1f772 100644 (file)
@@ -564,7 +564,7 @@ class LogService(SimpleService):
 
 
 class ExecutableService(SimpleService):
-    command_whitelist = ['exim']
+    command_whitelist = ['exim', 'postqueue']
 
     def __init__(self, configuration=None, name=None):
         self.command = ""
@@ -606,6 +606,14 @@ class ExecutableService(SimpleService):
             else:
                 self.error("Wrong command. Probably not on whitelist.")
                 return False
+        # test command and search for it in /usr/sbin or /sbin when failed
+        base = self.command[0]
+        if self._get_raw_data() is None:
+            for prefix in ['/sbin/', '/usr/sbin/']:
+                self.command[0] = prefix + base
+                if self._get_raw_data() is not None:
+                    break
+
         if self._get_data() is None or len(self._get_data()) == 0:
             return False
         return True
index a179dd9e19852a167d17b0fd24fc327990c7af36..f68ce7e57c9950d1223be0fc628a4a9481cf8b18 100644 (file)
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-# Description: squid netdata python.d plugin
+# Description: squid netdata python.d module
 # Author: Pawel Krupa (paulfantom)
 
 from base import NetSocketService
index a4b2e7104346f465558afa7c427e507b0e8469f0..060331cdcc12c20ba076b4d7a2048443963fbb3a 100644 (file)
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-# Description: tomcat netdata python.d plugin
+# Description: tomcat netdata python.d module
 # Author: Pawel Krupa (paulfantom)
 
 from base import UrlService