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