]> arthur.barton.de Git - netdata.git/blob - charts.d/tomcat.chart.sh
removing username/password from url in error message as these are variables now.
[netdata.git] / charts.d / tomcat.chart.sh
1 #!/bin/bash
2
3 # Description: Tomcat netdata charts.d plugin
4 # Author: Jorge Romero
5
6 # the URL to download tomcat status info
7 tomcat_url="http://localhost:8080/manager/status?XML=true"
8
9 # set tomcat user/password here
10 tomcatUser=""
11 tomcatPassword=""
12
13 # _update_every is a special variable - it holds the number of seconds
14 # between the calls of the _update() function
15 tomcat_update_every=
16
17 tomcat_priority=60000
18
19 # convert tomcat floating point values
20 # to integer using this multiplier
21 # this only affects precision - the values
22 # will be in the proper units
23 tomcat_decimal_detail=1000000
24
25 # used by volume chart to convert bytes to KB
26 tomcat_decimal_KB_detail=1000
27
28 tomcat_check() {
29
30         require_cmd xmlstarlet || return 1
31
32         tomcat_get
33         if [ $? -ne 0 ]
34                 then
35                 echo >&2 "tomcat: cannot find status page on URL '${tomcat_url}'. Please set tomcat_url='http://localhost:8080/manager/status?XML=true'"
36                 return 1
37         fi
38
39         # this should return:
40         #  - 0 to enable the chart
41         #  - 1 to disable the chart
42
43         return 0
44 }
45
46 tomcat_get() {
47         # Collect tomcat values
48         mapfile -t lines < <(curl -u "$tomcatUser":"$tomcatPassword" -Ss "$tomcat_url" |\
49                 xmlstarlet sel \
50                         -t -m "/status/jvm/memory" -v @free \
51                         -n -m "/status/connector[@name='\"http-bio-8080\"']/threadInfo" -v @currentThreadCount \
52                         -n -v @currentThreadsBusy \
53                         -n -m "/status/connector[@name='\"http-bio-8080\"']/requestInfo" -v @requestCount \
54                         -n -v @bytesSent -n -)
55
56         tomcat_jvm_freememory="${lines[0]}"
57         tomcat_threads="${lines[1]}"
58         tomcat_threads_busy="${lines[2]}"
59         tomcat_accesses="${lines[3]}"
60         tomcat_volume="${lines[4]}"
61
62         return 0
63 }
64
65 # _create is called once, to create the charts
66 tomcat_create() {
67         cat <<EOF
68 CHART tomcat.accesses '' "tomcat requests" "requests/s" statistics tomcat.accesses area $((tomcat_priority + 8)) $tomcat_update_every
69 DIMENSION accesses '' incremental
70 CHART tomcat.volume '' "tomcat volume" "KB/s" volume tomcat.volume area $((tomcat_priority + 5)) $tomcat_update_every
71 DIMENSION volume '' incremental divisor ${tomcat_decimal_KB_detail}
72 CHART tomcat.threads '' "tomcat threads" "current threads" statistics tomcat.threads line $((tomcat_priority + 6)) $tomcat_update_every
73 DIMENSION current '' absolute 1
74 DIMENSION busy '' absolute 1
75 CHART tomcat.jvm '' "JVM Free Memory" "MB" statistics tomcat.jvm area $((tomcat_priority + 8)) $tomcat_update_every
76 DIMENSION jvm '' absolute 1 ${tomcat_decimal_detail}
77 EOF
78         return 0
79 }
80
81 # _update is called continiously, to collect the values
82 tomcat_update() {
83         local reqs net
84         # the first argument to this function is the microseconds since last update
85         # pass this parameter to the BEGIN statement (see bellow).
86
87         # do all the work to collect / calculate the values
88         # for each dimension
89         # remember: KEEP IT SIMPLE AND SHORT
90
91         tomcat_get || return 1
92
93         # write the result of the work.
94         cat <<VALUESEOF
95 BEGIN tomcat.accesses $1
96 SET accesses = $((tomcat_accesses))
97 END
98 BEGIN tomcat.volume $1
99 SET volume = $((tomcat_volume))
100 END
101 BEGIN tomcat.threads $1
102 SET current = $((tomcat_threads))
103 SET busy = $((tomcat_threads_busy))
104 END
105 BEGIN tomcat.jvm $1
106 SET jvm = $((tomcat_jvm_freememory))
107 END
108 VALUESEOF
109
110         return 0
111 }