~ubuntu-branches/ubuntu/saucy/munin/saucy

« back to all changes in this revision

Viewing changes to plugins/node.d/jmx_tomcat_dbpools.in

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-06-11 12:54:28 UTC
  • mfrom: (8.1.30 sid)
  • Revision ID: package-import@ubuntu.com-20120611125428-k8z25s77rp755vxe
Tags: 2.0.0-1ubuntu1
* Resync with Debian unstable.
* d/munin-node.upstart,munin.upstart: Add upstart configurations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!@@PERL@@ -w
 
2
# -*- perl -*-
 
3
 
 
4
=head1 NAME
 
5
 
 
6
jmx_tomcat_dbpools - Plugin to monitor the database connection pools of a Tomcat application server via JMX
 
7
 
 
8
=head1 APPLICABLE SYSTEMS
 
9
 
 
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.
 
11
 
 
12
Any JVM that supports JMX should in theory do.
 
13
 
 
14
=head1 CONFIGURATION
 
15
 
 
16
  [jmx_tomcat_dbpools*]
 
17
    env.ip 127.0.0.1
 
18
    env.port 5400
 
19
    env.username monitorRole
 
20
    env.password SomethingSecret
 
21
    # The critical and warning levels are in % of the pool size
 
22
    env.critical 90
 
23
    env.warning 70
 
24
 
 
25
    env.JRE_HOME /usr/lib/jvm/java-6-sun/jre
 
26
 
 
27
Needed configuration on the Tomcat side: add
 
28
 
 
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
 
33
 
 
34
to CATALINA_OPTS in your startup scripts.
 
35
 
 
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.
 
40
 
 
41
jmxremote.password:
 
42
 monitorRole SomethingSecret
 
43
 
 
44
jmxremote.access:
 
45
 monitorRole readonly
 
46
 
 
47
=head1 BUGS
 
48
 
 
49
No encryption supported in the JMX connection.
 
50
 
 
51
=head1 AUTHORS
 
52
 
 
53
=encoding UTF-8
 
54
 
 
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.
 
58
 
 
59
Previous work on JMX plugin by Aleksey Studnev. Support for
 
60
authentication added by Ingvar Hagelund, Redpill Linpro AS.
 
61
 
 
62
=head1 LICENSE
 
63
 
 
64
GPLv2
 
65
 
 
66
=head1 MAGIC MARKERS
 
67
 
 
68
 #%# family=manual
 
69
 
 
70
=cut
 
71
 
 
72
use strict;
 
73
 
 
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";
 
79
 
 
80
if($ENV{'JRE_HOME'}) {
 
81
    $java="$ENV{'JRE_HOME'}/bin/java";
 
82
}
 
83
 
 
84
sub config() {
 
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\": $!";
 
86
 
 
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";
 
91
 
 
92
    while(my $line = <CMD>) {
 
93
        chomp($line);
 
94
        if($line =~ /^[^\t]+,name="([^\t"]+)"\t([^\t]+)\t([^\t]+)$/) {
 
95
            my $max   = $3;
 
96
            my $label = $1;
 
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";
 
102
            }
 
103
            if(defined $ENV{'warning'}) {
 
104
                print "$field.warning " . ($max * $ENV{'warning'} / 100), "\n";
 
105
            }
 
106
        }
 
107
    }
 
108
    close(CMD);
 
109
}
 
110
 
 
111
sub fetch() {
 
112
 
 
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\": $!";
 
119
 
 
120
    while(my $line = <CMD>) {
 
121
        chomp($line);
 
122
        if($line =~ /^[^\t]+,name="([^\t"]+)"\t([^\t]+)\t([^\t]+)$/) {
 
123
            my $num   = $3;
 
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";
 
127
        }
 
128
    }
 
129
    close(CMD);
 
130
}
 
131
 
 
132
$ENV{'ip'} = $ip;
 
133
$ENV{'port'} = $port;
 
134
 
 
135
if(defined $ARGV[0] and $ARGV[0] eq "config") {
 
136
    config();
 
137
} else {
 
138
    fetch();
 
139
}
 
140
 
 
141
# vim: ts=4:ai:et:syntax=perl