File: jmx_tomcat_dbpools.in

package info (click to toggle)
munin 2.0.76-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,064 kB
  • sloc: perl: 11,684; java: 1,924; sh: 1,632; makefile: 636; javascript: 365; python: 267
file content (141 lines) | stat: -rw-r--r-- 4,381 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!@@PERL@@ -w
# -*- perl -*-

=head1 NAME

jmx_tomcat_dbpools - Plugin to monitor the database connection pools of a Tomcat application server via JMX

=head1 APPLICABLE SYSTEMS

Tested with Tomcat 5.5/6.0 on Sun JVM 6. Please use this plugin as a template for other application-server specific monitoring.

Any JVM that supports JMX should in theory do.

=head1 CONFIGURATION

  [jmx_tomcat_dbpools*]
    env.ip 127.0.0.1
    env.port 5400
    env.username monitorRole
    env.password SomethingSecret
    # The critical and warning levels are in % of the pool size
    env.critical 90
    env.warning 70

    env.JRE_HOME /usr/lib/jvm/java-6-sun/jre

Needed configuration on the Tomcat side: add

  -Dcom.sun.management.jmxremote \
  -Dcom.sun.management.jmxremote.port=5400 \
  -Dcom.sun.management.jmxremote.ssl=false \
  -Dcom.sun.management.jmxremote.authenticate=false

to CATALINA_OPTS in your startup scripts.

Replace authenticate=false with
  -Dcom.sun.management.jmxremote.password.file=/etc/tomcat/jmxremote.password \
  -Dcom.sun.management.jmxremote.access.file=/etc/tomcat/jmxremote.access
 ...if you want authentication.

jmxremote.password:
 monitorRole SomethingSecret

jmxremote.access:
 monitorRole readonly

=head1 BUGS

No encryption supported in the JMX connection.

=head1 AUTHORS

=encoding UTF-8

Code written by Jimmy Olsen, Redpill Linpro AS. This code also
uses code written by Mo Amini, Diyar Amin and Younes Hajji,
Høgskolen i Oslo/Oslo University College.

Previous work on JMX plugin by Aleksey Studnev. Support for
authentication added by Ingvar Hagelund, Redpill Linpro AS.

=head1 LICENSE

GPLv2

=head1 MAGIC MARKERS

 #%# family=manual

=cut

use strict;

my $beans="Catalina:type=DataSource,class=javax.sql.DataSource,name=*";
my $munin_jar='@@JAVALIBDIR@@/munin-jmx-plugins.jar';
my $java='@@JAVARUN@@';
my $ip=$ENV{'ip'} || "127.0.0.1";
my $port=$ENV{'port'} || "5400";

if($ENV{'JRE_HOME'}) {
    $java="$ENV{'JRE_HOME'}/bin/java";
}

sub config() {
    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\": $!";

    print "graph_title Tomcat database pool overview\n";
    print "graph_vlabel current connections\n";
    print "graph_info Shows the number of connections used for every pool in a Tomcat instance\n";
    print "graph_category tomcat\n";

    while(my $line = <CMD>) {
        chomp($line);
        if($line =~ /^[^\t]+,name="([^\t"]+)"\t([^\t]+)\t([^\t]+)$/) {
            my $max   = $3;
            my $label = $1;
            my $field = "v" . $label; # Prefix with a known good char, as field names can't start with a number
            $field =~ s/[^A-Za-z0-9]/_/g;
            print "$field.label $label\n$field.max $max\n";
            if(defined $ENV{'critical'}) {
                print "$field.critical " . ($max * $ENV{'critical'} / 100), "\n";
            }
            if(defined $ENV{'warning'}) {
                print "$field.warning " . ($max * $ENV{'warning'} / 100), "\n";
            }
        }
    }
    close(CMD);
}

sub fetch() {

    # Fetch bean values (through jmx) via the command line. We basically run the class "org.munin.plugin.jmx.Beans"
    # with the parameters <bean> and <filter>, the <bean> being a bean pattern to fetch (in this case
    # "Catalina:type=DataSource,class=javax.sql.DataSource,name=*", and <filter> being "numActive" (the single field
    # we're actually interested in). We can fetch multiple fields by listing them all as parameters, or list all fields
    # by not supplying a filter (only a bean).
    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\": $!";

    while(my $line = <CMD>) {
        chomp($line);
        if($line =~ /^[^\t]+,name="([^\t"]+)"\t([^\t]+)\t([^\t]+)$/) {
            my $num   = $3;
            my $field = "v" . $1; # Prefix with a known good char, as field names can't start with a number
            $field =~ s/[^A-Za-z0-9]/_/g;
            print "$field.value $num\n";
        }
    }
    close(CMD);
}

$ENV{'ip'} = $ip;
$ENV{'port'} = $port;

if(defined $ARGV[0] and $ARGV[0] eq "config") {
    config();
} else {
    fetch();
}

# vim: ts=4:ai:et:syntax=perl