# no need for shebang - this file is loaded from charts.d.plugin # Description: Tomcat netdata charts.d plugin # Author: Jorge Romero # the URL to download tomcat status info # 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 tomcat_update_every= tomcat_priority=60000 # convert tomcat floating point values # to integer using this multiplier # this only affects precision - the values # will be in the proper units tomcat_decimal_detail=1000000 # used by volume chart to convert bytes to KB tomcat_decimal_KB_detail=1000 tomcat_check() { require_cmd xmlstarlet || return 1 # check if url, username, passwords are set if [ -z "${tomcat_url}" ]; then echo >&2 "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 echo >&2 "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 echo >&2 "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: couldn't get to status page on URL '${tomcat_url}'."\ "Please make sure tomcat url, username and password are correct." return 1 fi # this should return: # - 0 to enable the chart # - 1 to disable the chart return 0 } tomcat_get() { # collect tomcat values tomcat_port="$(IFS=/ read -ra a <<< "$tomcat_url"; hostport=${a[2]}; echo "${hostport#*:}")" mapfile -t lines < <(curl -u "$tomcat_user":"$tomcat_password" -Ss ${tomcat_curl_opts} "$tomcat_url" |\ 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]}" tomcat_threads_busy="${lines[2]}" tomcat_accesses="${lines[3]}" tomcat_volume="${lines[4]}" return 0 } # _create is called once, to create the charts tomcat_create() { cat <