3 # Description: Tomcat netdata charts.d plugin
6 # the URL to download tomcat status info
7 # usually http://localhost:8080/manager/status?XML=true
10 # set tomcat username/password here
14 # _update_every is a special variable - it holds the number of seconds
15 # between the calls of the _update() function
20 # convert tomcat floating point values
21 # to integer using this multiplier
22 # this only affects precision - the values
23 # will be in the proper units
24 tomcat_decimal_detail=1000000
26 # used by volume chart to convert bytes to KB
27 tomcat_decimal_KB_detail=1000
31 require_cmd xmlstarlet || return 1
34 # check if url, username, passwords are set
35 if [ -z "${tomcat_url}" ]; then
36 echo >&2 "tomcat url is unset or set to the empty string"
39 if [ -z "${tomcatUser}" ]; then
40 echo >&2 "tomcat user is unset or set to the empty string"
43 if [ -z "${tomcatPassword}" ]; then
44 echo >&2 "tomcat password is unset or set to the empty string"
48 # check if we can get to tomcat's status page
52 echo >&2 "tomcat: couldn't get to status page on URL '${tomcat_url}'."\
53 "Please make sure tomcat url, username and password are correct."
58 # - 0 to enable the chart
59 # - 1 to disable the chart
65 # Collect tomcat values
66 mapfile -t lines < <(curl -u "$tomcatUser":"$tomcatPassword" -Ss "$tomcat_url" |\
68 -t -m "/status/jvm/memory" -v @free \
69 -n -m "/status/connector[@name='\"http-bio-8080\"']/threadInfo" -v @currentThreadCount \
70 -n -v @currentThreadsBusy \
71 -n -m "/status/connector[@name='\"http-bio-8080\"']/requestInfo" -v @requestCount \
72 -n -v @bytesSent -n -)
74 tomcat_jvm_freememory="${lines[0]}"
75 tomcat_threads="${lines[1]}"
76 tomcat_threads_busy="${lines[2]}"
77 tomcat_accesses="${lines[3]}"
78 tomcat_volume="${lines[4]}"
83 # _create is called once, to create the charts
86 CHART tomcat.accesses '' "tomcat requests" "requests/s" statistics tomcat.accesses area $((tomcat_priority + 8)) $tomcat_update_every
87 DIMENSION accesses '' incremental
88 CHART tomcat.volume '' "tomcat volume" "KB/s" volume tomcat.volume area $((tomcat_priority + 5)) $tomcat_update_every
89 DIMENSION volume '' incremental divisor ${tomcat_decimal_KB_detail}
90 CHART tomcat.threads '' "tomcat threads" "current threads" statistics tomcat.threads line $((tomcat_priority + 6)) $tomcat_update_every
91 DIMENSION current '' absolute 1
92 DIMENSION busy '' absolute 1
93 CHART tomcat.jvm '' "JVM Free Memory" "MB" statistics tomcat.jvm area $((tomcat_priority + 8)) $tomcat_update_every
94 DIMENSION jvm '' absolute 1 ${tomcat_decimal_detail}
99 # _update is called continiously, to collect the values
102 # the first argument to this function is the microseconds since last update
103 # pass this parameter to the BEGIN statement (see bellow).
105 # do all the work to collect / calculate the values
107 # remember: KEEP IT SIMPLE AND SHORT
109 tomcat_get || return 1
111 # write the result of the work.
113 BEGIN tomcat.accesses $1
114 SET accesses = $((tomcat_accesses))
116 BEGIN tomcat.volume $1
117 SET volume = $((tomcat_volume))
119 BEGIN tomcat.threads $1
120 SET current = $((tomcat_threads))
121 SET busy = $((tomcat_threads_busy))
124 SET jvm = $((tomcat_jvm_freememory))