Pythian Blog: Technical Track

Quick script to get list of all jmx beans

Recently I've needed to get information from running Cassandra processes, in order to determine which parameters to monitor. jconsole can be used for this, however if you're using a host on AWS, or in a bandwidth-limited environment, you might find that it takes way too long, especially if all you want to do for the moment is get a list of all beans and their attributes. jmxterm is a good solution for this - a command line interface to your jmx port. So here's a couple of utility scripts that you can use to get all the beans and each of their attributes using jmxterm. You may need to change $jar, $host, and $port in the perl script to fit your environment, and also maybe change the domains in the bash script. Then you should be able to simply run the bash script to get a list of each bean and its attributes. I found this useful when looking for the correct syntax to set up some nagios monitoring for cassandra. For example, here is a snippet of the output: [code] org.apache.cassandra.internal . . . Checking bean org.apache.cassandra.internal:type=FlushWriter %0 - ActiveCount (int, r) %1 - CompletedTasks (long, r) %2 - CurrentlyBlockedTasks (int, r) %3 - PendingTasks (long, r) %4 - TotalBlockedTasks (int, r) . . . [/code] [code lang="bash"]check_jmx!$HOSTADDRESS$!7199!-O org.apache.cassandra.internal:type=FlushWriter -A CurrentlyBlockedTask[/code]   [code lang="perl"]#!/usr/bin/env perl use strict; my $jar = "/home/ubuntu/jmxterm-1.0-alpha-4-uber.jar"; my $host = "10.176.66.219"; my $port = 7199; my $domain = shift @ARGV; my @beans = (); my $bean; my $size; for my $arg (@ARGV) { if ($arg =~ /^\w/) { push (@beans, $arg); } else { last; } } $size = @beans; $bean = join(' ',@beans) if ($size > 0); open JMX, "| java -jar $jar -n"; print JMX "open $host:$port\n"; print JMX "domain $domain \n"; if (defined $bean && length $bean > 0) { print JMX "bean $bean \n"; print JMX "info \n"; } else { print JMX "beans \n"; } print JMX "close\n"; close JMX;[/code]

No Comments Yet

Let us know what you think

Subscribe by email