E. Embed in script language

Back to Jmxterm index

Jmxterm is not designed to be a middle layer between JMX API and application. But with small effort, Jmxterm can be called in programmatic manner from script language such as PERL or Shell.

To wrap JMX with objects easy to call by scripting language such as goovy or beanshell, there are other technologies designed to help such scenario. For example Groovy JMX provides some classes that wraps an MBean and expose nice API. JMXTERM itself doesn't provide scripting features such as variable manupulation or flow control keywords.

However, since the commands in JMXTERM comes from standard input, modern script environment that handles stdin nicely, such as SHELL or PERL, can easily combine scripting feature with JMXTERM by using input pipe. Following example is a small PERL segment that connects to an MBean server and list domains.

# This Perl script open connection and call domains
# $jar stands for path of jmxterm jar file
open JMX, "| java -jar $jar -n";
print JMX "help \n";
 
my $host = "localhost";
my $port = 9991;
 
print JMX "open $host:$port\n";
print JMX "domains\n";
print JMX "close\n";
close JMX;

Following example is to call JMXTERM from shell. This particular command is useful when you want to get the PID of JVM process that listens to a known JMX port.

$ echo get -s -b java.lang:type=Runtime Name | \
java -jar target/jmxterm-1.0-alpha-3-uber.jar \
-l localhost:9991 -v silent -n
11383@happycow

Back to Jmxterm index


Add a New Comment
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License