Hi all,
I read about the monitoring with jmx but imo it is boring to use the same way every time - so here's an approach with the manager application of tomcat:
1. add something like
to the tomcat-users.xml file
2. copy the following in a file and mark it as executable (the values for port, user and password should be changed according to your environment):
4. add some userdefined items to your zabbix_agentd.conf, I use this:
5. add the items to your zabbix host configuration and start to monitor the state of your tomcat container 
the status page of the manager application supports much more infos about the tomcat server - feel free to extend the script.
disclaimer: I "stole" some of the code from a munin plugin
I read about the monitoring with jmx but imo it is boring to use the same way every time - so here's an approach with the manager application of tomcat:
1. add something like
Code:
<user username="zabbix" password="zabbix" roles="manager"/>
2. copy the following in a file and mark it as executable (the values for port, user and password should be changed according to your environment):
Code:
#!/usr/bin/perl -w
use strict;
my $ret = undef;
if(!eval "require LWP::UserAgent;") {
$ret = "LWP::UserAgent not found";
}
if(!eval "require XML::Simple;") {
$ret .= "XML::Simple not found";
}
my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://%s:%s\@127.0.0.1:%d/manager/status?XML=true";
my $PORT = exists $ENV{'ports'} ? $ENV{'ports'} : 8080;
my $USER = exists $ENV{'user'} ? $ENV{'user'} : "zabbix";
my $PASSWORD = exists $ENV{'password'} ? $ENV{'password'} : "zabbix";
my $TIMEOUT = exists $ENV{'timeout'} ? $ENV{'timeout'} : 30;
my $url = sprintf $URL, $USER, $PASSWORD, $PORT;
if(exists $ARGV[0] and $ARGV[0] eq "running") {
my $au = LWP::UserAgent->new(timeout => $TIMEOUT);
my $repsonse = $au->request(HTTP::Request->new('GET',$url));
if($repsonse->is_success and $repsonse->content =~ /<status>.*<\/status>/im) {
print "1\n";
exit 0;
} else {
print "0\n";
exit 1;
}
}
if(exists $ARGV[0] and $ARGV[0] eq "mem") {
my $ua = LWP::UserAgent->new(timeout => $TIMEOUT);
my $xs = new XML::Simple;
my $response = $ua->request(HTTP::Request->new('GET',$url));
my $xml = $xs->XMLin($response->content);
if($xml->{'jvm'}->{'memory'}->{'free'} && $xml->{'jvm'}->{'memory'}->{'total'}) {
print "" . ($xml->{'jvm'}->{'memory'}->{'total'} - $xml->{'jvm'}->{'memory'}->{'free'}) . "\n";
}
}
if(exists $ARGV[0] and $ARGV[0] eq "maxmem") {
my $ua = LWP::UserAgent->new(timeout => $TIMEOUT);
my $xs = new XML::Simple;
my $response = $ua->request(HTTP::Request->new('GET',$url));
my $xml = $xs->XMLin($response->content);
if($xml->{'jvm'}->{'memory'}->{'max'}) {
print "" . ($xml->{'jvm'}->{'memory'}->{'max'}) . "\n";
}
}
if(exists $ARGV[0] and $ARGV[0] eq "freemem") {
my $ua = LWP::UserAgent->new(timeout => $TIMEOUT);
my $xs = new XML::Simple;
my $response = $ua->request(HTTP::Request->new('GET',$url));
my $xml = $xs->XMLin($response->content);
if($xml->{'jvm'}->{'memory'}->{'free'}) {
print "" . ($xml->{'jvm'}->{'memory'}->{'free'}) . "\n";
}
}
Code:
UserParameter=tomcat.running,/opt/zabbix-scripts/tomcat_running.pl running UserParameter=tomcat.mem,/opt/zabbix-scripts/tomcat_running.pl mem UserParameter=tomcat.maxmem,/opt/zabbix-scripts/tomcat_running.pl maxmem UserParameter=tomcat.freemem,/opt/zabbix-scripts/tomcat_running.pl freemem

the status page of the manager application supports much more infos about the tomcat server - feel free to extend the script.
disclaimer: I "stole" some of the code from a munin plugin
Comment