]> arthur.barton.de Git - netdata.git/blob - charts.d/tomcat.chart.sh
rename chart fields to avoid conflicts with backends; fixes #1962
[netdata.git] / charts.d / tomcat.chart.sh
1 # no need for shebang - this file is loaded from charts.d.plugin
2
3 # netdata
4 # real-time performance and health monitoring, done right!
5 # (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6 # GPL v3+
7 #
8 # Contributed by @jgeromero with PR #277
9
10 # Description: Tomcat netdata charts.d plugin
11 # Author: Jorge Romero
12
13 # the URL to download tomcat status info
14 # usually http://localhost:8080/manager/status?XML=true
15 tomcat_url=""
16 tomcat_curl_opts=""
17
18 # set tomcat username/password here
19 tomcat_user=""
20 tomcat_password=""
21
22 # _update_every is a special variable - it holds the number of seconds
23 # between the calls of the _update() function
24 tomcat_update_every=
25
26 tomcat_priority=60000
27
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
33
34 # used by volume chart to convert bytes to KB
35 tomcat_decimal_KB_detail=1000
36
37 tomcat_check() {
38
39         require_cmd xmlstarlet || return 1
40
41
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"
45                 return 1
46         fi
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"
51                         return 1
52                 else
53                         tomcat_user="${tomcatUser}"
54                 fi
55         fi
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"
60                         return 1
61                 else
62                         tomcat_password="${tomcatPassword}"
63                 fi
64         fi
65
66         # check if we can get to tomcat's status page
67         tomcat_get
68         if [ $? -ne 0 ]
69                 then
70                 error "cannot get to status page on URL '${tomcat_url}'. Please make sure tomcat url, username and password are correct."
71                 return 1
72         fi
73
74         # this should return:
75         #  - 0 to enable the chart
76         #  - 1 to disable the chart
77
78         return 0
79 }
80
81 tomcat_get() {
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" |\
85                 run xmlstarlet sel \
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 -)
91
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]}"
97
98         return 0
99 }
100
101 # _create is called once, to create the charts
102 tomcat_create() {
103         cat <<EOF
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}
113 EOF
114         return 0
115 }
116
117 # _update is called continiously, to collect the values
118 tomcat_update() {
119         local reqs net
120         # the first argument to this function is the microseconds since last update
121         # pass this parameter to the BEGIN statement (see bellow).
122
123         # do all the work to collect / calculate the values
124         # for each dimension
125         # remember: KEEP IT SIMPLE AND SHORT
126
127         tomcat_get || return 1
128
129         # write the result of the work.
130         cat <<VALUESEOF
131 BEGIN tomcat.accesses $1
132 SET accesses = $((tomcat_accesses))
133 END
134 BEGIN tomcat.volume $1
135 SET volume = $((tomcat_volume))
136 END
137 BEGIN tomcat.threads $1
138 SET current = $((tomcat_threads))
139 SET busy = $((tomcat_threads_busy))
140 END
141 BEGIN tomcat.jvm $1
142 SET jvm = $((tomcat_jvm_freememory))
143 END
144 VALUESEOF
145
146         return 0
147 }