3 # Description: Tomcat netdata charts.d plugin
6 # the URL to download tomcat status info
7 # usually http://localhost:8080/manager/status?XML=true
11 # set tomcat username/password here
15 # _update_every is a special variable - it holds the number of seconds
16 # between the calls of the _update() function
21 # convert tomcat floating point values
22 # to integer using this multiplier
23 # this only affects precision - the values
24 # will be in the proper units
25 tomcat_decimal_detail=1000000
27 # used by volume chart to convert bytes to KB
28 tomcat_decimal_KB_detail=1000
32 require_cmd xmlstarlet || return 1
35 # check if url, username, passwords are set
36 if [ -z "${tomcat_url}" ]; then
37 echo >&2 "tomcat url is unset or set to the empty string"
40 if [ -z "${tomcat_user}" ]; then
41 # check backwards compatibility
42 if [ -z "${tomcatUser}" ]; then
43 echo >&2 "tomcat user is unset or set to the empty string"
46 tomcat_user="${tomcatUser}"
49 if [ -z "${tomcat_password}" ]; then
50 # check backwards compatibility
51 if [ -z "${tomcatPassword}" ]; then
52 echo >&2 "tomcat password is unset or set to the empty string"
55 tomcat_password="${tomcatPassword}"
59 # check if we can get to tomcat's status page
63 echo >&2 "tomcat: couldn't get to status page on URL '${tomcat_url}'."\
64 "Please make sure tomcat url, username and password are correct."
69 # - 0 to enable the chart
70 # - 1 to disable the chart
76 # collect tomcat values
77 tomcat_port="$(IFS=/ read -ra a <<< "$tomcat_url"; hostport=${a[2]}; echo "${hostport#*:}")"
78 mapfile -t lines < <(curl -u "$tomcat_user":"$tomcat_password" -Ss ${tomcat_curl_opts} "$tomcat_url" |\
80 -t -m "/status/jvm/memory" -v @free \
81 -n -m "/status/connector[@name='\"http-bio-$tomcat_port\"']/threadInfo" -v @currentThreadCount \
82 -n -v @currentThreadsBusy \
83 -n -m "/status/connector[@name='\"http-bio-$tomcat_port\"']/requestInfo" -v @requestCount \
84 -n -v @bytesSent -n -)
86 tomcat_jvm_freememory="${lines[0]}"
87 tomcat_threads="${lines[1]}"
88 tomcat_threads_busy="${lines[2]}"
89 tomcat_accesses="${lines[3]}"
90 tomcat_volume="${lines[4]}"
95 # _create is called once, to create the charts
98 CHART tomcat.accesses '' "tomcat requests" "requests/s" statistics tomcat.accesses area $((tomcat_priority + 8)) $tomcat_update_every
99 DIMENSION accesses '' incremental
100 CHART tomcat.volume '' "tomcat volume" "KB/s" volume tomcat.volume area $((tomcat_priority + 5)) $tomcat_update_every
101 DIMENSION volume '' incremental divisor ${tomcat_decimal_KB_detail}
102 CHART tomcat.threads '' "tomcat threads" "current threads" statistics tomcat.threads line $((tomcat_priority + 6)) $tomcat_update_every
103 DIMENSION current '' absolute 1
104 DIMENSION busy '' absolute 1
105 CHART tomcat.jvm '' "JVM Free Memory" "MB" statistics tomcat.jvm area $((tomcat_priority + 8)) $tomcat_update_every
106 DIMENSION jvm '' absolute 1 ${tomcat_decimal_detail}
111 # _update is called continiously, to collect the values
114 # the first argument to this function is the microseconds since last update
115 # pass this parameter to the BEGIN statement (see bellow).
117 # do all the work to collect / calculate the values
119 # remember: KEEP IT SIMPLE AND SHORT
121 tomcat_get || return 1
123 # write the result of the work.
125 BEGIN tomcat.accesses $1
126 SET accesses = $((tomcat_accesses))
128 BEGIN tomcat.volume $1
129 SET volume = $((tomcat_volume))
131 BEGIN tomcat.threads $1
132 SET current = $((tomcat_threads))
133 SET busy = $((tomcat_threads_busy))
136 SET jvm = $((tomcat_jvm_freememory))