6
jmx_tomcat_dbpools - Plugin to monitor the database connection pools of a Tomcat application server via JMX
8
=head1 APPLICABLE SYSTEMS
10
Tested with Tomcat 5.5/6.0 on Sun JVM 6. Please use this plugin as a template for other application-server specific monitoring.
12
Any JVM that supports JMX should in theory do.
19
env.username monitorRole
20
env.password SomethingSecret
21
# The critical and warning levels are in % of the pool size
25
env.JRE_HOME /usr/lib/jvm/java-6-sun/jre
27
Needed configuration on the Tomcat side: add
29
-Dcom.sun.management.jmxremote \
30
-Dcom.sun.management.jmxremote.port=5400 \
31
-Dcom.sun.management.jmxremote.ssl=false \
32
-Dcom.sun.management.jmxremote.authenticate=false
34
to CATALINA_OPTS in your startup scripts.
36
Replace authenticate=false with
37
-Dcom.sun.management.jmxremote.password.file=/etc/tomcat/jmxremote.password \
38
-Dcom.sun.management.jmxremote.access.file=/etc/tomcat/jmxremote.access
39
...if you want authentication.
42
monitorRole SomethingSecret
49
No encryption supported in the JMX connection.
55
Code written by Jimmy Olsen, Redpill Linpro AS. This code also
56
uses code written by Mo Amini, Diyar Amin and Younes Hajji,
57
Høgskolen i Oslo/Oslo University College.
59
Previous work on JMX plugin by Aleksey Studnev. Support for
60
authentication added by Ingvar Hagelund, Redpill Linpro AS.
74
my $beans="Catalina:type=DataSource,class=javax.sql.DataSource,name=*";
75
my $munin_jar='@@JAVALIBDIR@@/munin-jmx-plugins.jar';
76
my $java='@@JAVARUN@@';
77
my $ip=$ENV{'ip'} || "127.0.0.1";
78
my $port=$ENV{'port'} || "5400";
80
if($ENV{'JRE_HOME'}) {
81
$java="$ENV{'JRE_HOME'}/bin/java";
85
open(CMD, "-|", $java, "-cp", $munin_jar, "org.munin.plugin.jmx.Beans", $beans, "maxActive") or die "Error: could not run \"$java -cp $munin_jar org.munin.plugin.jmx.Beans maxActive\": $!";
87
print "graph_title Tomcat database pool overview\n";
88
print "graph_vlabel current connections\n";
89
print "graph_info Shows the number of connections used for every pool in a Tomcat instance\n";
90
print "graph_category tomcat\n";
92
while(my $line = <CMD>) {
94
if($line =~ /^[^\t]+,name="([^\t"]+)"\t([^\t]+)\t([^\t]+)$/) {
97
my $field = "v" . $label; # Prefix with a known good char, as field names can't start with a number
98
$field =~ s/[^A-Za-z0-9]/_/g;
99
print "$field.label $label\n$field.max $max\n";
100
if(defined $ENV{'critical'}) {
101
print "$field.critical " . ($max * $ENV{'critical'} / 100), "\n";
103
if(defined $ENV{'warning'}) {
104
print "$field.warning " . ($max * $ENV{'warning'} / 100), "\n";
113
# Fetch bean values (through jmx) via the command line. We basically run the class "org.munin.plugin.jmx.Beans"
114
# with the parameters <bean> and <filter>, the <bean> being a bean pattern to fetch (in this case
115
# "Catalina:type=DataSource,class=javax.sql.DataSource,name=*", and <filter> being "numActive" (the single field
116
# we're actually interested in). We can fetch multiple fields by listing them all as parameters, or list all fields
117
# by not supplying a filter (only a bean).
118
open(CMD, "-|", $java, "-cp", $munin_jar, "org.munin.plugin.jmx.Beans", $beans, "numActive") or die "Error: could not run \"$java -cp $munin_jar org.munin.plugin.jmx.Beans maxActive\": $!";
120
while(my $line = <CMD>) {
122
if($line =~ /^[^\t]+,name="([^\t"]+)"\t([^\t]+)\t([^\t]+)$/) {
124
my $field = "v" . $1; # Prefix with a known good char, as field names can't start with a number
125
$field =~ s/[^A-Za-z0-9]/_/g;
126
print "$field.value $num\n";
133
$ENV{'port'} = $port;
135
if(defined $ARGV[0] and $ARGV[0] eq "config") {
141
# vim: ts=4:ai:et:syntax=perl