X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=python.d%2Ftomcat.chart.py;h=c20f85e1ecd2818a6b87386e1f2e8d1c368f7591;hb=909e26f825bc1f6f907231761412c885331fec7e;hp=060331cdcc12c20ba076b4d7a2048443963fbb3a;hpb=509c50df3bce82fc6bae3974347619fa97591bad;p=netdata.git diff --git a/python.d/tomcat.chart.py b/python.d/tomcat.chart.py index 060331cd..c20f85e1 100644 --- a/python.d/tomcat.chart.py +++ b/python.d/tomcat.chart.py @@ -3,37 +3,42 @@ # Author: Pawel Krupa (paulfantom) from base import UrlService -import xml.etree.ElementTree as ET # phone home... +from re import compile + +try: + from urlparse import urlparse +except ImportError: + from urllib.parse import urlparse # default module values (can be overridden per job in `config`) # update_every = 2 priority = 60000 -retries = 5 +retries = 60 # 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"], + 'options': [None, "Requests", "requests/s", "statistics", "tomcat.accesses", "area"], 'lines': [ - ["accesses"] + ["requestCount", 'accesses', 'incremental'] ]}, 'volume': { - 'options': [None, "tomcat volume", "KB/s", "volume", "tomcat.volume", "area"], + 'options': [None, "Volume", "KB/s", "volume", "tomcat.volume", "area"], 'lines': [ - ["volume", None, 'incremental'] + ["bytesSent", 'volume', 'incremental', 1, 1024] ]}, 'threads': { - 'options': [None, "tomcat threads", "current threads", "statistics", "tomcat.threads", "line"], + 'options': [None, "Threads", "current threads", "statistics", "tomcat.threads", "line"], 'lines': [ - ["current", None, "absolute"], - ["busy", None, "absolute"] + ["currentThreadCount", 'current', "absolute"], + ["currentThreadsBusy", 'busy', "absolute"] ]}, 'jvm': { 'options': [None, "JVM Free Memory", "MB", "statistics", "tomcat.jvm", "area"], 'lines': [ - ["jvm", None, "absolute"] + ["free", None, "absolute", 1, 1048576] ]} } @@ -41,38 +46,31 @@ CHARTS = { 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.url = self.configuration.get('url', "http://127.0.0.1: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 check(self): + netloc = urlparse(self.url).netloc.rpartition(':') + if netloc[1] == ':': port = netloc[2] + else: port = 80 + + self.regex_jvm = compile(r'.*?') + self.regex_connector = compile(r'[a-z-]+%s.*?/connector' % port) + self.regex = compile(r'([\w]+)=\\?[\'\"](\d+)\\?[\'\"]') + + return UrlService.check(self) 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") + data = self._get_raw_data() + if data: + jvm = self.regex_jvm.findall(data) or [''] + connector = self.regex_connector.findall(data) or [''] + data = dict(self.regex.findall(''.join([jvm[0], connector[0]]))) + + return data or None - 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