1 # no need for shebang - this file is loaded from charts.d.plugin
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 error "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 error "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 error "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 error "cannot get to status page on URL '${tomcat_url}'. Please make sure tomcat url, username and password are correct."
68 # - 0 to enable the chart
69 # - 1 to disable the chart
75 # collect tomcat values
76 tomcat_port="$(IFS=/ read -ra a <<< "$tomcat_url"; hostport=${a[2]}; echo "${hostport#*:}")"
77 mapfile -t lines < <(run curl -u "$tomcat_user":"$tomcat_password" -Ss ${tomcat_curl_opts} "$tomcat_url" |\
79 -t -m "/status/jvm/memory" -v @free \
80 -n -m "/status/connector[@name='\"http-bio-$tomcat_port\"']/threadInfo" -v @currentThreadCount \
81 -n -v @currentThreadsBusy \
82 -n -m "/status/connector[@name='\"http-bio-$tomcat_port\"']/requestInfo" -v @requestCount \
83 -n -v @bytesSent -n -)
85 tomcat_jvm_freememory="${lines[0]}"
86 tomcat_threads="${lines[1]}"
87 tomcat_threads_busy="${lines[2]}"
88 tomcat_accesses="${lines[3]}"
89 tomcat_volume="${lines[4]}"
94 # _create is called once, to create the charts
97 CHART tomcat.accesses '' "tomcat requests" "requests/s" statistics tomcat.accesses area $((tomcat_priority + 8)) $tomcat_update_every
98 DIMENSION accesses '' incremental
99 CHART tomcat.volume '' "tomcat volume" "KB/s" volume tomcat.volume area $((tomcat_priority + 5)) $tomcat_update_every
100 DIMENSION volume '' incremental divisor ${tomcat_decimal_KB_detail}
101 CHART tomcat.threads '' "tomcat threads" "current threads" statistics tomcat.threads line $((tomcat_priority + 6)) $tomcat_update_every
102 DIMENSION current '' absolute 1
103 DIMENSION busy '' absolute 1
104 CHART tomcat.jvm '' "JVM Free Memory" "MB" statistics tomcat.jvm area $((tomcat_priority + 8)) $tomcat_update_every
105 DIMENSION jvm '' absolute 1 ${tomcat_decimal_detail}
110 # _update is called continiously, to collect the values
113 # the first argument to this function is the microseconds since last update
114 # pass this parameter to the BEGIN statement (see bellow).
116 # do all the work to collect / calculate the values
118 # remember: KEEP IT SIMPLE AND SHORT
120 tomcat_get || return 1
122 # write the result of the work.
124 BEGIN tomcat.accesses $1
125 SET accesses = $((tomcat_accesses))
127 BEGIN tomcat.volume $1
128 SET volume = $((tomcat_volume))
130 BEGIN tomcat.threads $1
131 SET current = $((tomcat_threads))
132 SET busy = $((tomcat_threads_busy))
135 SET jvm = $((tomcat_jvm_freememory))