JmxProxyClient is an Object Oriented interface for JmxProxy which is a part of the manager app in Tomcat. It offers a quick and easy access to MBeans via HTTP and can be used in shell scripts, performance graphing apps, monitoring apps etc. Currently it's only available in Perl.
Features in this release:
TODOs:
use JmxProxyClient;
use JmxProxyClient::MBean;
# Create a new instance of JmxProxyClient
my $jpc = new JmxProxyClient(
server => 'localhost',
port => 8080,
user => 'man',
password=> 'man123',
);
# Fetch all available MBeans
my @allBeans = $jpc->get_all_mbeans;
for my $mbean (@allBeans) {
print $mbean->name . "\n";
my %attrs = $mbean->get_attributes;
while (my ($attr, $val) = each (%attrs)) {
print "\t" . $attr . ": " . $val . "\n";
}
}
use JmxProxyClient;
use JmxProxyClient::MBean;
# Create a new instance of JmxProxyClient
my $jpc = new JmxProxyClient(
server => 'localhost',
port => 8080,
user => 'man',
password=> 'man123',
);
# Run a query and display results
my @mbeans = $jpc->search("Catalina:type=ThreadPool,*");
for my $mbean (@mbeans) {
print $mbean->name . "\n";
my %attrs = $mbean->attributes;
while (my ($attr, $val) = each (%attrs)) {
print "\t" . $attr . ": " . $val . "\n";
}
print "\n\n";
printf "Busy/Current = %d/%d = %.2f\n",
$attrs{currentThreadsBusy},
$attrs{currentThreadCount},
$attrs{currentThreadsBusy} / $attrs{currentThreadCount};
print "\n\n";
}
use strict;
use JmxProxyClient;
use JmxProxyClient::MBean;
# Create a new instance of JmxProxyClient
my $jpc = new JmxProxyClient(
server => 'localhost',
port => 8080,
user => 'man',
password=> 'man123',
);
my $mem = "java.lang:type=Memory";
# Using hash of results
my %memstats = $jpc->mbean($mem)->heap_mem_usage;
while (my($key, $val) = each(%memstats)) {
printf "\t%s\t=%d\n", $key, $val;
}
# Querying individual mem areas
foreach ((qw/committed max used init/)) {
printf "\t%20s= %d\n", $_, $jpc->mbean($mem)->heap_mem_usage($_);
}
use strict;
use JmxProxyClient;
use JmxProxyClient::MBean;
# Create a new instance of JmxProxyClient
my $jpc = new JmxProxyClient(
server => 'localhost',
port => 8080,
user => 'man',
password=> 'man123',
);
# Run a query and display results
my $gm_prefix = "tomcat_";
my $mbean_name = "Catalina:type=ThreadPool,name=http-8080";
while (1) {
foreach (("currentThreadsBusy", "currentThreadCount")) {
my %metric = (
name => $gm_prefix . $mbean_name . "_" . $_,
type => "int32",
units => "threads",
value => $jpc->mbean($mbean_name)->get($_)
);
exec(gmetric(%metric));
}
sleep 15;
}
sub gmetric {
my %params = @_;
# Replace illegal chars with _
$params{'name'} =~ s/[^a-zA-Z0-9_]/_/g;
my $cmd = "/usr/bin/gmetric --name='%s' --type='%s' --units='%s' --value='";
# Set the correct format for the value
if ($params{type} =~ /.*int.*/) { $cmd .= "%d'"; }
elsif ($params{type} =~ /(float)|(double)/) { $cmd .= "%s'"; }
else { $cmd .= "%s'"; }
return sprintf $cmd, $params{'name'}, $params{'type'}, $params{'units'}, $params{'value'};
}