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
You need the "-n" on the "java -jar" command in the perl example.
Thanks for pointing out!
Does anyone know how to script this within windows using a batch file?
it's supposed to be the same
echo "get -s -b java.lang:type=Runtime Name" | java -jar …
What does the '-s' stand for? I keep getting an exception using the 1.0-alpha-4 version if I try to use that.
For example
$>bean
java.lang:type=Memory
$>get Verbose
#mbean = java.lang:type=Memory:
Verbose = false;
$>get -s Verbose
#mbean = java.lang:type=Memory:
false