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...
10 # default module values (can be overridden per job in `config`)
15 # charts order (can be overridden if you want less charts, or different order)
16 ORDER = ['accesses', 'volume', 'threads', 'jvm']
20 'options': [None, "tomcat requests", "requests/s", "statistics", "tomcat.accesses", "area"],
25 'options': [None, "tomcat volume", "KB/s", "volume", "tomcat.volume", "area"],
27 ["volume", None, 'incremental']
30 'options': [None, "tomcat threads", "current threads", "statistics", "tomcat.threads", "line"],
32 ["current", None, "absolute"],
33 ["busy", None, "absolute"]
36 'options': [None, "JVM Free Memory", "MB", "statistics", "tomcat.jvm", "area"],
38 ["jvm", None, "absolute"]
43 class Service(UrlService):
44 def __init__(self, configuration=None, name=None):
45 UrlService.__init__(self, configuration=configuration, name=name)
46 if len(self.url) == 0:
47 self.url = "http://localhost:8080/manager/status?XML=true"
49 self.definitions = CHARTS
52 for i in self.url.split('/'):
55 self.port = i.split(':')[-1]
64 Format data received from http request
68 raw = self._get_raw_data()
69 data = ET.fromstring(raw)
70 memory = data.find('./jvm/memory')
71 threads = data.find("./connector[@name='\"http-bio-" + str(self.port) + "\"']/threadInfo")
72 requests = data.find("./connector[@name='\"http-bio-" + str(self.port) + "\"']/requestInfo")
74 return {'accesses': requests.attrib['requestCount'],
75 'volume': requests.attrib['bytesSent'],
76 'current': threads.attrib['currentThreadCount'],
77 'busy': threads.attrib['currentThreadsBusy'],
78 'jvm': memory.attrib['free']}
79 except (ValueError, AttributeError):
81 except SyntaxError as e:
82 self.error("Tomcat module needs python 2.7 at least. Stopping")
84 except Exception as e: