]> arthur.barton.de Git - netdata.git/blobdiff - charts.d/tomcat.chart.sh
Merge pull request #542 from ktsaou/master
[netdata.git] / charts.d / tomcat.chart.sh
index ee17d1757ec80e36426025f56a07b07afcd40a96..b0eddc7f0dac66345b79ad55b017a321b53ae5ac 100755 (executable)
@@ -6,6 +6,7 @@
 # the URL to download tomcat status info
 # usually http://localhost:8080/manager/status?XML=true
 tomcat_url=""
+tomcat_curl_opts=""
 
 # set tomcat username/password here
 tomcatUser=""
@@ -33,15 +34,15 @@ tomcat_check() {
 
        # check if url, username, passwords are set
        if [ -z "${tomcat_url}" ]; then
-         echo "tomcat url is unset or set to the empty string"
+               echo >&2 "tomcat url is unset or set to the empty string"
                return 1
        fi
        if [ -z "${tomcatUser}" ]; then
-         echo "tomcat user is unset or set to the empty string"
+               echo >&2 "tomcat user is unset or set to the empty string"
                return 1
        fi
        if [ -z "${tomcatPassword}" ]; then
-         echo "tomcat password is unset or set to the empty string"
+               echo >&2 "tomcat password is unset or set to the empty string"
                return 1
        fi
 
@@ -49,7 +50,8 @@ tomcat_check() {
        tomcat_get
        if [ $? -ne 0 ]
                then
-               echo >&2 "tomcat: couldn't get to status page on URL '${tomcat_url}'. Please make sure tomcat url, username and password are correct."
+               echo >&2 "tomcat: couldn't get to status page on URL '${tomcat_url}'."\
+               "Please make sure tomcat url, username and password are correct."
                return 1
        fi
 
@@ -61,13 +63,14 @@ tomcat_check() {
 }
 
 tomcat_get() {
-       # Collect tomcat values
-       mapfile -t lines < <(curl -u "$tomcatUser":"$tomcatPassword" -Ss "$tomcat_url" |\
+       # collect tomcat values
+       tomcat_port="$(IFS=/ read -ra a <<< "$tomcat_url"; hostport=${a[2]}; echo "${hostport#*:}")"
+       mapfile -t lines < <(curl -u "$tomcatUser":"$tomcatPassword" -Ss ${tomcat_curl_opts} "$tomcat_url" |\
                xmlstarlet sel \
                        -t -m "/status/jvm/memory" -v @free \
-                       -n -m "/status/connector[@name='\"http-bio-8080\"']/threadInfo" -v @currentThreadCount \
+                       -n -m "/status/connector[@name='\"http-bio-$tomcat_port\"']/threadInfo" -v @currentThreadCount \
                        -n -v @currentThreadsBusy \
-                       -n -m "/status/connector[@name='\"http-bio-8080\"']/requestInfo" -v @requestCount \
+                       -n -m "/status/connector[@name='\"http-bio-$tomcat_port\"']/requestInfo" -v @requestCount \
                        -n -v @bytesSent -n -)
 
        tomcat_jvm_freememory="${lines[0]}"