@cryptotaxi247 / netdata-1 / commits / 9194a4e0b

As suggested, tweaked tomcat_url for better handling, added array for single xml response, switched to xmlstarlet for parsing and added dependency check.

Jorge Romero committed Apr 20, 2016 at 15:08 UTC 9194a4e0b6076a5f9efff64c4580288336041c52
1 file changed +12 -8
charts.d/tomcat.chart.sh
+12 -8
@@ -1,10 +1,10 @@
1 -#!/bin/sh
1 +#!/bin/bash
2
3 # Description: Tomcat netdata charts.d plugin
4 # Author: Jorge Romero
5
6 # the URL to download tomcat status info
7 -tomcat_url="http://<user>:<password>@localhost:8080/manager/status?XML=true"
7 +tomcat_url="http://localhost:8080/manager/status?XML=true"
8
9 # _update_every is a special variable - it holds the number of seconds
10 # between the calls of the _update() function
@@ -23,6 +23,8 @@ tomcat_decimal_KB_detail=1000
23
24 tomcat_check() {
25
26 + require_cmd xmlstarlet || return 1
27 +
28 tomcat_get
29 if [ $? -ne 0 ]
30 then
@@ -38,12 +40,14 @@ tomcat_check() {
40 }
41
42 tomcat_get() {
41 -
42 - tomcat_accesses=$(curl -s "${tomcat_url}" | xmllint --xpath "string(/status/connector[@name='\"http-bio-8080\"']/requestInfo/@requestCount)" - )
43 - tomcat_volume=$(curl -s "${tomcat_url}" | xmllint --xpath "string(/status/connector[@name='\"http-bio-8080\"']/requestInfo/@bytesSent)" - )
44 - tomcat_threads=$(curl -s "${tomcat_url}" | xmllint --xpath "string(/status/connector[@name='\"http-bio-8080\"']/threadInfo/@currentThreadCount)" -)
45 - tomcat_threads_busy=$(curl -s "${tomcat_url}" | xmllint --xpath "string(/status/connector[@name='\"http-bio-8080\"']/threadInfo/@currentThreadsBusy)" -)
46 - tomcat_jvm_freememory=$(curl -s "${tomcat_url}" | xmllint --xpath "string(/status/jvm/memory/@free)" - )
43 + # Collect tomcat values
44 + mapfile -t lines < <(curl -s "$tomcat_url" | xmlstarlet sel -t -m "/status/jvm/memory" -v @free -n -m "/status/connector[@name='\"http-bio-8080\"']/threadInfo" -v @currentThreadCount -n -v @currentThreadsBusy -n -m "/status/connector[@name='\"http-bio-8080\"']/requestInfo" -v @requestCount -n -v @bytesSent -n -)
45 +
46 + tomcat_jvm_freememory="${lines[0]}"
47 + tomcat_threads="${lines[1]}"
48 + tomcat_threads_busy="${lines[2]}"
49 + tomcat_accesses="${lines[3]}"
50 + tomcat_volume="${lines[4]}"
51
52 return 0
53 }