working version of tomcat.chart.py
paulfantom committed
Jul 6, 2016 at 20:53 UTC
2c0ce5338813444ea5e0dfc2f4e71cbad897749c
4 files changed
+89
conf.d/Makefile.am
+1
@@ -27,6 +27,7 @@ dist_pythonconfig_DATA = \
27
python.d/nginx.conf \
28
python.d/phpfpm.conf \
29
python.d/squid.conf \
30
+ python.d/tomcat.conf \
31
$(NULL)
32
33
conf.d/python.d/tomcat.conf
new
+9
@@ -0,0 +1,9 @@
1
+# Example configuration of tomcat.chart.py
2
+# YAML format
3
+
4
+retries: 10
5
+
6
+local:
7
+ url: "http://localhost:8080/manager/status?XML=true"
8
+ user: ""
9
+ password: ""
python.d/Makefile.am
+1
@@ -13,6 +13,7 @@ dist_python_SCRIPTS = \
13
apache_cache.chart.py \
14
hddtemp.chart.py \
15
squid.chart.py \
16
+ tomcat.chart.py \
17
python-modules-installer.sh \
18
$(NULL)
19
python.d/tomcat.chart.py
new
+78
@@ -0,0 +1,78 @@
1
+# -*- coding: utf-8 -*-
2
+# Description: tomcat netdata python.d plugin
3
+# Author: Pawel Krupa (paulfantom)
4
+
5
+from base import UrlService
6
+import xml.etree.ElementTree as ET # phone home...
7
+
8
+# default module values (can be overridden per job in `config`)
9
+# update_every = 2
10
+priority = 60000
11
+retries = 5
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, "tomcat requests", "requests/s", "statistics", "tomcat.accesses", "area"],
19
+ 'lines': [
20
+ ["accesses"]
21
+ ]},
22
+ 'volume': {
23
+ 'options': [None, "tomcat volume", "KB/s", "volume", "tomcat.volume", "area"],
24
+ 'lines': [
25
+ ["volume", None, 'incremental']
26
+ ]},
27
+ 'threads': {
28
+ 'options': [None, "tomcat threads", "current threads", "statistics", "tomcat.threads", "line"],
29
+ 'lines': [
30
+ ["current", None, "absolute"],
31
+ ["busy", None, "absolute"]
32
+ ]},
33
+ 'jvm': {
34
+ 'options': [None, "JVM Free Memory", "MB", "statistics", "tomcat.jvm", "area"],
35
+ 'lines': [
36
+ ["jvm", None, "absolute"]
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
+ if len(self.url) == 0:
45
+ self.url = "http://localhost:8080/manager/status?XML=true"
46
+ self.order = ORDER
47
+ self.definitions = CHARTS
48
+ # get port from url
49
+ self.port = 0
50
+ for i in self.url.split('/'):
51
+ try:
52
+ int(i[-1])
53
+ self.port = i.split(':')[-1]
54
+ break
55
+ except:
56
+ pass
57
+ if self.port == 0:
58
+ self.port = 80
59
+
60
+ def _get_data(self):
61
+ """
62
+ Format data received from http request
63
+ :return: dict
64
+ """
65
+ try:
66
+ raw = self._get_raw_data()
67
+ data = ET.fromstring(raw)
68
+ memory = data.find('./jvm/memory')
69
+ threads = data.find("./connector[@name='\"http-bio-" + str(self.port) + "\"']/threadInfo")
70
+ requests = data.find("./connector[@name='\"http-bio-" + str(self.port) + "\"']/requestInfo")
71
+
72
+ return {'accesses': requests.attrib['requestCount'],
73
+ 'volume': requests.attrib['bytesSent'],
74
+ 'current': threads.attrib['currentThreadCount'],
75
+ 'busy': threads.attrib['currentThreadsBusy'],
76
+ 'jvm': memory.attrib['free']}
77
+ except (ValueError, AttributeError):
78
+ return None