]> arthur.barton.de Git - netdata.git/blob - python.d/tomcat.chart.py
tomcat plugin: replace xml parse with regex
[netdata.git] / python.d / tomcat.chart.py
1 # -*- coding: utf-8 -*-
2 # Description: tomcat netdata python.d module
3 # Author: Pawel Krupa (paulfantom)
4
5 from base import UrlService
6 from re import compile
7
8 # default module values (can be overridden per job in `config`)
9 # update_every = 2
10 priority = 60000
11 retries = 60
12
13 # charts order (can be overridden if you want less charts, or different order)
14 ORDER = ['accesses', 'volume', 'threads', 'jvm']
15
16 CHARTS = {
17     'accesses': {
18         'options': [None, "Requests", "requests/s", "statistics", "tomcat.accesses", "area"],
19         'lines': [
20             ["requestCount", 'accesses', 'incremental']
21         ]},
22     'volume': {
23         'options': [None, "Volume", "KB/s", "volume", "tomcat.volume", "area"],
24         'lines': [
25             ["bytesSent", 'volume', 'incremental', 1, 1024]
26         ]},
27     'threads': {
28         'options': [None, "Threads", "current threads", "statistics", "tomcat.threads", "line"],
29         'lines': [
30             ["currentThreadCount", 'current', "absolute"],
31             ["currentThreadsBusy", 'busy', "absolute"]
32         ]},
33     'jvm': {
34         'options': [None, "JVM Free Memory", "MB", "statistics", "tomcat.jvm", "area"],
35         'lines': [
36             ["free", None, "absolute", 1, 1048576]
37         ]}
38 }
39
40
41 class Service(UrlService):
42     def __init__(self, configuration=None, name=None):
43         UrlService.__init__(self, configuration=configuration, name=name)
44         self.url = self.configuration.get('url', "http://127.0.0.1:8080/manager/status?XML=true")
45         self.order = ORDER
46         self.definitions = CHARTS
47         self.regex = compile(r'([\w]+)=\\?[\'\"](\d+)\\?[\'\"]')
48
49     def check(self):
50         if not self.url.endswith('manager/status?XML=true'):
51             self.error('Bad url(%s). Must be http://<ip.address>:<port>/manager/status?XML=true' % self.url)
52             return False
53
54         return UrlService.check(self)
55
56     def _get_data(self):
57         """
58         Format data received from http request
59         :return: dict
60         """
61         data = self._get_raw_data()
62         if data: data = dict(self.regex.findall(data))
63         
64         return data or None