@cryptotaxi247 / netdata-1 / commits / 7516186fe

tomcat charts.d plugin

Jorge Romero committed Apr 19, 2016 at 12:20 UTC 7516186fe199ebd60236b60952b3ee33b6397c1d
1 file changed +97
charts.d/tomcat.chart.sh new
+97
@@ -0,0 +1,97 @@
1 +#!/bin/sh
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://<user>:<password>@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 + tomcat_get
27 + if [ $? -ne 0 ]
28 + then
29 + echo >&2 "tomcat: cannot find stub_status on URL '${tomcat_url}'. Please set tomcat_url='http://<user>:<password>@localhost:8080/manager/status?XML=true'"
30 + return 1
31 + fi
32 +
33 + # this should return:
34 + # - 0 to enable the chart
35 + # - 1 to disable the chart
36 +
37 + return 0
38 +}
39 +
40 +tomcat_get() {
41 +
42 + tomcat_accesses=$(curl -s "${tomcat_url}" | xmllint --xpath "string(/status/connector[@name='\"http-bio-8080\"']/requestInfo/@requestCount)" - )
43 + tomcat_volume=$(curl -s "${tomcat_url}" | xmllint --xpath "string(/status/connector[@name='\"http-bio-8080\"']/requestInfo/@bytesSent)" - )
44 + tomcat_threads=$(curl -s "${tomcat_url}" | xmllint --xpath "string(/status/connector[@name='\"http-bio-8080\"']/threadInfo/@currentThreadCount)" -)
45 + tomcat_threads_busy=$(curl -s "${tomcat_url}" | xmllint --xpath "string(/status/connector[@name='\"http-bio-8080\"']/threadInfo/@currentThreadsBusy)" -)
46 + tomcat_jvm_freememory=$(curl -s "${tomcat_url}" | xmllint --xpath "string(/status/jvm/memory/@free)" - )
47 +
48 + return 0
49 +}
50 +
51 +# _create is called once, to create the charts
52 +tomcat_create() {
53 + cat <<EOF
54 +CHART tomcat.accesses '' "tomcat requests" "requests/s" statistics tomcat.accesses area $[tomcat_priority + 8] $tomcat_update_every
55 +DIMENSION accesses '' incremental
56 +CHART tomcat.volume '' "tomcat volume" "KB/s" volume tomcat.volume area $[tomcat_priority + 5] $tomcat_update_every
57 +DIMENSION volume '' incremental divisor ${tomcat_decimal_KB_detail}
58 +CHART tomcat.threads '' "tomcat threads" "current threads" statistics tomcat.threads line $[tomcat_priority + 6] $tomcat_update_every
59 +DIMENSION current '' absolute 1
60 +DIMENSION busy '' absolute 1
61 +CHART tomcat.jvm '' "JVM Free Memory" "MB" statistics tomcat.jvm area $[tomcat_priority + 8] $tomcat_update_every
62 +DIMENSION jvm '' absolute 1 ${tomcat_decimal_detail}
63 +EOF
64 + return 0
65 +}
66 +
67 +# _update is called continiously, to collect the values
68 +tomcat_update() {
69 + local reqs net
70 + # the first argument to this function is the microseconds since last update
71 + # pass this parameter to the BEGIN statement (see bellow).
72 +
73 + # do all the work to collect / calculate the values
74 + # for each dimension
75 + # remember: KEEP IT SIMPLE AND SHORT
76 +
77 + tomcat_get || return 1
78 +
79 + # write the result of the work.
80 + cat <<VALUESEOF
81 +BEGIN tomcat.accesses $1
82 +SET accesses = $[tomcat_accesses]
83 +END
84 +BEGIN tomcat.volume $1
85 +SET volume = $[tomcat_volume]
86 +END
87 +BEGIN tomcat.threads $1
88 +SET current = $[tomcat_threads]
89 +SET busy = $[tomcat_threads_busy]
90 +END
91 +BEGIN tomcat.jvm $1
92 +SET jvm = $[tomcat_jvm_freememory]
93 +END
94 +VALUESEOF
95 +
96 + return 0
97 +}