1 # -*- coding: utf-8 -*-
2 # Description: tomcat netdata python.d module
3 # Author: Pawel Krupa (paulfantom)
5 # Python version higher than 2.7 is needed to run this module.
7 from base import UrlService
8 import xml.etree.ElementTree as ET # phone home...
9 #from xml.parsers.expat import errors
11 # default module values (can be overridden per job in `config`)
16 # charts order (can be overridden if you want less charts, or different order)
17 ORDER = ['accesses', 'volume', 'threads', 'jvm']
21 'options': [None, "tomcat requests", "requests/s", "statistics", "tomcat.accesses", "area"],
23 ["accesses", None, 'incremental']
26 'options': [None, "tomcat volume", "KB/s", "volume", "tomcat.volume", "area"],
28 ["volume", None, 'incremental', 1, 1024]
31 'options': [None, "tomcat threads", "current threads", "statistics", "tomcat.threads", "line"],
33 ["current", None, "absolute"],
34 ["busy", None, "absolute"]
37 'options': [None, "JVM Free Memory", "MB", "statistics", "tomcat.jvm", "area"],
39 ["jvm", None, "absolute", 1, 1048576]
44 class Service(UrlService):
45 def __init__(self, configuration=None, name=None):
46 UrlService.__init__(self, configuration=configuration, name=name)
47 if len(self.url) == 0:
48 self.url = "http://localhost:8080/manager/status?XML=true"
50 self.definitions = CHARTS
54 if UrlService.check(self):
59 for i in self.url.split('/'):
62 self.port = i.split(':')[-1]
69 test = self._get_data()
70 if test is None or len(test) == 0:
77 Format data received from http request
81 raw = self._get_raw_data()
83 data = ET.fromstring(raw)
84 except ET.ParseError as e:
85 # if e.code == errors.codes[errors.XML_ERROR_JUNK_AFTER_DOC_ELEMENT]:
87 end = raw.find('</status>')
91 data = ET.fromstring(raw)
95 memory = data.find('./jvm/memory')
96 threads = data.find("./connector[@name='\"http-bio-" + str(self.port) + "\"']/threadInfo")
97 requests = data.find("./connector[@name='\"http-bio-" + str(self.port) + "\"']/requestInfo")
99 return {'accesses': requests.attrib['requestCount'],
100 'volume': requests.attrib['bytesSent'],
101 'current': threads.attrib['currentThreadCount'],
102 'busy': threads.attrib['currentThreadsBusy'],
103 'jvm': memory.attrib['free']}
104 except (ValueError, AttributeError) as e:
107 except SyntaxError as e:
108 self.error("Tomcat module needs python 2.7 at least. Stopping")
110 except Exception as e: