]> arthur.barton.de Git - netdata.git/blobdiff - charts.d/tomcat.chart.sh
fix numa plugin to work only on the expected values; fixes #1868
[netdata.git] / charts.d / tomcat.chart.sh
old mode 100755 (executable)
new mode 100644 (file)
index 55476f4..44a92c8
@@ -1,10 +1,23 @@
-#!/bin/bash
+# no need for shebang - this file is loaded from charts.d.plugin
+
+# netdata
+# real-time performance and health monitoring, done right!
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
+# GPL v3+
+#
+# Contributed by @jgeromero with PR #277
 
 # Description: Tomcat netdata charts.d plugin
 # Author: Jorge Romero
 
 # the URL to download tomcat status info
-tomcat_url="http://localhost:8080/manager/status?XML=true"
+# usually http://localhost:8080/manager/status?XML=true
+tomcat_url=""
+tomcat_curl_opts=""
+
+# set tomcat username/password here
+tomcat_user=""
+tomcat_password=""
 
 # _update_every is a special variable - it holds the number of seconds
 # between the calls of the _update() function
@@ -25,10 +38,36 @@ tomcat_check() {
 
        require_cmd xmlstarlet || return 1
 
+
+       # check if url, username, passwords are set
+       if [ -z "${tomcat_url}" ]; then
+               error "tomcat url is unset or set to the empty string"
+               return 1
+       fi
+       if [ -z "${tomcat_user}" ]; then
+               # check backwards compatibility
+               if [ -z "${tomcatUser}" ]; then         
+               error "tomcat user is unset or set to the empty string"
+                       return 1
+               else
+                       tomcat_user="${tomcatUser}"
+               fi
+       fi
+       if [ -z "${tomcat_password}" ]; then
+               # check backwards compatibility
+               if [ -z "${tomcatPassword}" ]; then
+               error "tomcat password is unset or set to the empty string"
+                       return 1
+               else
+                       tomcat_password="${tomcatPassword}"
+               fi
+       fi
+
+       # check if we can get to tomcat's status page
        tomcat_get
        if [ $? -ne 0 ]
                then
-               echo >&2 "tomcat: cannot find stub_status on URL '${tomcat_url}'. Please set tomcat_url='http://<user>:<password>@localhost:8080/manager/status?XML=true'"
+               error "cannot get to status page on URL '${tomcat_url}'. Please make sure tomcat url, username and password are correct."
                return 1
        fi
 
@@ -40,8 +79,15 @@ tomcat_check() {
 }
 
 tomcat_get() {
-       # Collect tomcat values
-       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 -)
+       # collect tomcat values
+       tomcat_port="$(IFS=/ read -ra a <<< "$tomcat_url"; hostport=${a[2]}; echo "${hostport#*:}")"
+       mapfile -t lines < <(run curl -u "$tomcat_user":"$tomcat_password" -Ss ${tomcat_curl_opts} "$tomcat_url" |\
+               run xmlstarlet sel \
+                       -t -m "/status/jvm/memory" -v @free \
+                       -n -m "/status/connector[@name='\"http-bio-$tomcat_port\"']/threadInfo" -v @currentThreadCount \
+                       -n -v @currentThreadsBusy \
+                       -n -m "/status/connector[@name='\"http-bio-$tomcat_port\"']/requestInfo" -v @requestCount \
+                       -n -v @bytesSent -n -)
 
        tomcat_jvm_freememory="${lines[0]}"
        tomcat_threads="${lines[1]}"
@@ -55,14 +101,14 @@ tomcat_get() {
 # _create is called once, to create the charts
 tomcat_create() {
        cat <<EOF
-CHART tomcat.accesses '' "tomcat requests" "requests/s" statistics tomcat.accesses area $[tomcat_priority + 8] $tomcat_update_every
+CHART tomcat.accesses '' "tomcat requests" "requests/s" statistics tomcat.accesses area $((tomcat_priority + 8)) $tomcat_update_every
 DIMENSION accesses '' incremental
-CHART tomcat.volume '' "tomcat volume" "KB/s" volume tomcat.volume area $[tomcat_priority + 5] $tomcat_update_every
+CHART tomcat.volume '' "tomcat volume" "KB/s" volume tomcat.volume area $((tomcat_priority + 5)) $tomcat_update_every
 DIMENSION volume '' incremental divisor ${tomcat_decimal_KB_detail}
-CHART tomcat.threads '' "tomcat threads" "current threads" statistics tomcat.threads line $[tomcat_priority + 6] $tomcat_update_every
+CHART tomcat.threads '' "tomcat threads" "current threads" statistics tomcat.threads line $((tomcat_priority + 6)) $tomcat_update_every
 DIMENSION current '' absolute 1
 DIMENSION busy '' absolute 1
-CHART tomcat.jvm '' "JVM Free Memory" "MB" statistics tomcat.jvm area $[tomcat_priority + 8] $tomcat_update_every
+CHART tomcat.jvm '' "JVM Free Memory" "MB" statistics tomcat.jvm area $((tomcat_priority + 8)) $tomcat_update_every
 DIMENSION jvm '' absolute 1 ${tomcat_decimal_detail}
 EOF
        return 0
@@ -83,17 +129,17 @@ tomcat_update() {
        # write the result of the work.
        cat <<VALUESEOF
 BEGIN tomcat.accesses $1
-SET accesses = $[tomcat_accesses]
+SET accesses = $((tomcat_accesses))
 END
 BEGIN tomcat.volume $1
-SET volume = $[tomcat_volume]
+SET volume = $((tomcat_volume))
 END
 BEGIN tomcat.threads $1
-SET current = $[tomcat_threads]
-SET busy = $[tomcat_threads_busy]
+SET current = $((tomcat_threads))
+SET busy = $((tomcat_threads_busy))
 END
 BEGIN tomcat.jvm $1
-SET jvm = $[tomcat_jvm_freememory]
+SET jvm = $((tomcat_jvm_freememory))
 END
 VALUESEOF