1 # no need for shebang - this file is loaded from charts.d.plugin
4 # real-time performance and health monitoring, done right!
5 # (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
8 # Contributed by @jgeromero with PR #277
10 # Description: Tomcat netdata charts.d plugin
11 # Author: Jorge Romero
13 # the URL to download tomcat status info
14 # usually http://localhost:8080/manager/status?XML=true
18 # set tomcat username/password here
22 # _update_every is a special variable - it holds the number of seconds
23 # between the calls of the _update() function
28 # convert tomcat floating point values
29 # to integer using this multiplier
30 # this only affects precision - the values
31 # will be in the proper units
32 tomcat_decimal_detail=1000000
34 # used by volume chart to convert bytes to KB
35 tomcat_decimal_KB_detail=1000
39 require_cmd xmlstarlet || return 1
42 # check if url, username, passwords are set
43 if [ -z "${tomcat_url}" ]; then
44 error "tomcat url is unset or set to the empty string"
47 if [ -z "${tomcat_user}" ]; then
48 # check backwards compatibility
49 if [ -z "${tomcatUser}" ]; then
50 error "tomcat user is unset or set to the empty string"
53 tomcat_user="${tomcatUser}"
56 if [ -z "${tomcat_password}" ]; then
57 # check backwards compatibility
58 if [ -z "${tomcatPassword}" ]; then
59 error "tomcat password is unset or set to the empty string"
62 tomcat_password="${tomcatPassword}"
66 # check if we can get to tomcat's status page
70 error "cannot get to status page on URL '${tomcat_url}'. Please make sure tomcat url, username and password are correct."
75 # - 0 to enable the chart
76 # - 1 to disable the chart
82 # collect tomcat values
83 tomcat_port="$(IFS=/ read -ra a <<< "$tomcat_url"; hostport=${a[2]}; echo "${hostport#*:}")"
84 mapfile -t lines < <(run curl -u "$tomcat_user":"$tomcat_password" -Ss ${tomcat_curl_opts} "$tomcat_url" |\
86 -t -m "/status/jvm/memory" -v @free \
87 -n -m "/status/connector[@name='\"http-bio-$tomcat_port\"']/threadInfo" -v @currentThreadCount \
88 -n -v @currentThreadsBusy \
89 -n -m "/status/connector[@name='\"http-bio-$tomcat_port\"']/requestInfo" -v @requestCount \
90 -n -v @bytesSent -n -)
92 tomcat_jvm_freememory="${lines[0]}"
93 tomcat_threads="${lines[1]}"
94 tomcat_threads_busy="${lines[2]}"
95 tomcat_accesses="${lines[3]}"
96 tomcat_volume="${lines[4]}"
101 # _create is called once, to create the charts
104 CHART tomcat.accesses '' "tomcat requests" "requests/s" statistics tomcat.accesses area $((tomcat_priority + 8)) $tomcat_update_every
105 DIMENSION accesses '' incremental
106 CHART tomcat.volume '' "tomcat volume" "KB/s" volume tomcat.volume area $((tomcat_priority + 5)) $tomcat_update_every
107 DIMENSION volume '' incremental divisor ${tomcat_decimal_KB_detail}
108 CHART tomcat.threads '' "tomcat threads" "current threads" statistics tomcat.threads line $((tomcat_priority + 6)) $tomcat_update_every
109 DIMENSION current '' absolute 1
110 DIMENSION busy '' absolute 1
111 CHART tomcat.jvm '' "JVM Free Memory" "MB" statistics tomcat.jvm area $((tomcat_priority + 8)) $tomcat_update_every
112 DIMENSION jvm '' absolute 1 ${tomcat_decimal_detail}
117 # _update is called continiously, to collect the values
120 # the first argument to this function is the microseconds since last update
121 # pass this parameter to the BEGIN statement (see bellow).
123 # do all the work to collect / calculate the values
125 # remember: KEEP IT SIMPLE AND SHORT
127 tomcat_get || return 1
129 # write the result of the work.
131 BEGIN tomcat.accesses $1
132 SET accesses = $((tomcat_accesses))
134 BEGIN tomcat.volume $1
135 SET volume = $((tomcat_volume))
137 BEGIN tomcat.threads $1
138 SET current = $((tomcat_threads))
139 SET busy = $((tomcat_threads_busy))
142 SET jvm = $((tomcat_jvm_freememory))