]> arthur.barton.de Git - netdata.git/commitdiff
working version of tomcat.chart.py
authorpaulfantom <paulfantom@gmail.com>
Wed, 6 Jul 2016 18:53:45 +0000 (20:53 +0200)
committerpaulfantom <paulfantom@gmail.com>
Wed, 6 Jul 2016 18:53:45 +0000 (20:53 +0200)
conf.d/Makefile.am
conf.d/python.d/tomcat.conf [new file with mode: 0644]
python.d/Makefile.am
python.d/tomcat.chart.py [new file with mode: 0644]

index 6b643bdb37423e930bf98a91ce5740808f67420a..faf4ecdfbc654b2b5871be6c05c4142e3d5906ee 100644 (file)
@@ -27,6 +27,7 @@ dist_pythonconfig_DATA = \
        python.d/nginx.conf \
        python.d/phpfpm.conf \
        python.d/squid.conf \
+       python.d/tomcat.conf \
        $(NULL)
 
 
diff --git a/conf.d/python.d/tomcat.conf b/conf.d/python.d/tomcat.conf
new file mode 100644 (file)
index 0000000..efcb671
--- /dev/null
@@ -0,0 +1,9 @@
+# Example configuration of tomcat.chart.py
+# YAML format
+
+retries: 10
+
+local:
+  url: "http://localhost:8080/manager/status?XML=true"
+  user: ""
+  password: ""
index 553e56d0760f2388b7713705fa3c672b8b64316d..239d9826fa79ad451470e4ab5bf9dea625cc9d94 100644 (file)
@@ -13,6 +13,7 @@ dist_python_SCRIPTS = \
        apache_cache.chart.py \
        hddtemp.chart.py \
        squid.chart.py \
+       tomcat.chart.py \
        python-modules-installer.sh \
        $(NULL)
 
diff --git a/python.d/tomcat.chart.py b/python.d/tomcat.chart.py
new file mode 100644 (file)
index 0000000..a4b2e71
--- /dev/null
@@ -0,0 +1,78 @@
+# -*- coding: utf-8 -*-
+# Description: tomcat netdata python.d plugin
+# Author: Pawel Krupa (paulfantom)
+
+from base import UrlService
+import xml.etree.ElementTree as ET  # phone home...
+
+# 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 = ['accesses', 'volume', 'threads', 'jvm']
+
+CHARTS = {
+    'accesses': {
+        'options': [None, "tomcat requests", "requests/s", "statistics", "tomcat.accesses", "area"],
+        'lines': [
+            ["accesses"]
+        ]},
+    'volume': {
+        'options': [None, "tomcat volume", "KB/s", "volume", "tomcat.volume", "area"],
+        'lines': [
+            ["volume", None, 'incremental']
+        ]},
+    'threads': {
+        'options': [None, "tomcat threads", "current threads", "statistics", "tomcat.threads", "line"],
+        'lines': [
+            ["current", None, "absolute"],
+            ["busy", None, "absolute"]
+        ]},
+    'jvm': {
+        'options': [None, "JVM Free Memory", "MB", "statistics", "tomcat.jvm", "area"],
+        'lines': [
+            ["jvm", None, "absolute"]
+        ]}
+}
+
+
+class Service(UrlService):
+    def __init__(self, configuration=None, name=None):
+        UrlService.__init__(self, configuration=configuration, name=name)
+        if len(self.url) == 0:
+            self.url = "http://localhost:8080/manager/status?XML=true"
+        self.order = ORDER
+        self.definitions = CHARTS
+        # get port from url
+        self.port = 0
+        for i in self.url.split('/'):
+            try:
+                int(i[-1])
+                self.port = i.split(':')[-1]
+                break
+            except:
+                pass
+        if self.port == 0:
+            self.port = 80
+
+    def _get_data(self):
+        """
+        Format data received from http request
+        :return: dict
+        """
+        try:
+            raw = self._get_raw_data()
+            data = ET.fromstring(raw)
+            memory = data.find('./jvm/memory')
+            threads = data.find("./connector[@name='\"http-bio-" + str(self.port) + "\"']/threadInfo")
+            requests = data.find("./connector[@name='\"http-bio-" + str(self.port) + "\"']/requestInfo")
+
+            return {'accesses': requests.attrib['requestCount'],
+                    'volume': requests.attrib['bytesSent'],
+                    'current': threads.attrib['currentThreadCount'],
+                    'busy': threads.attrib['currentThreadsBusy'],
+                    'jvm': memory.attrib['free']}
+        except (ValueError, AttributeError):
+            return None