Introducing MBeanCmd
MBeanCmd is a command-line tool written in Java for interacting with MBeans on any J2EE server. It can:
- Send commands to:
- Any number of MBeans
- On any number of J2EE servers
- In a periodical way
- Receive the result of that command, for example the CPU usage rate measured by the JVM mbean
- Use this result to:
- Display it directly on the console
- Output it to a text file
- Display it on a graph
- Push it to a JASMINe Event Switch
It does not depend on any J2EE package. The various outputs (for example, file, graph and JASMINe Event Switch) can be combined.
MBeans and your J2EE server
What is an MBean ?
MBeans are managed beans, i.e. Java objects that represent resources to be managed. An MBean has a management interface consisting of:
- Named and typed attributes that can be read and written
- Named and typed operations that can be invoked
- Typed notifications that can be emitted by the MBean
For example, an MBean representing an application's configuration could have attributes representing the different configuration parameters, such as a cache size.
- Reading the CacheSize attribute would return the current size of the cache.
- Writing CacheSize would update the size of the cache, potentially changing the behavior of the running application.
MBeans in JOnAS
Getting to the list of available MBeans in JOnAS is pretty straightforward, thanks to the JOnAS Administration interface: simply click on
MBeans on the menu on the left and the list of currently deployed MBeans will appear.
Connecting to MBeans on a J2EE server
Note that not all those MBeans are available remotely: to connect to any MBean, one needs to use a
connetor MBean. To get the list of the connector MBeans and their addresses in JOnAS, click on
Other MBeans - Connectors. In the
Attributes tab of a connector MBean, you can see its JMX Service URL:

This is the URL MBeanCmd will connect to in order to manage any MBean.
Using MBeanCmd
Getting help
To launch MBeanCmd, just go to the folder where mbean.jar is present and launch:
Since no option has been specified, this will simply display the help. To display the help for a command, say poll, type in:
java -jar mbean.jar help poll
Note that the help file for poll is quite large: it includes the usage options and the DTD to use to display a graph.
Defining targets
To use MBeanCmd for capturing statistics periodically (
poll and
stat commands), you first need to define which J2EE server(s) you're targeting. This can be done in two ways:
- If you're targeting only one server, define jasmine.jmx.url to the connector's URL.
- If you're targeting multiple servers, create a file called jmxurls.properties (file name can be changed by redefining jasmine.jmx.file). This file contains the list of servers and the default target. For example:
jasmine.jmx.url.j1 = service:jmx:rmi:///jndi/rmi://localhost:1099/jrmpconnector_jonas0
jasmine.jmx.url.j3 = service:jmx:rmi:///jndi/rmi://localhost:1099/jrmpconnector_jonas1
jasmine.jmx.url.j2 = service:jmx:rmi:///jndi/rmi://192.168.7.5:1099/jrmpconnector_jonas
jasmine.jmx.default.target = j1
Usage example: output the number of threads
If we browse the JOnAS Administration interface, we see that the JVM J2EE Bean (called in our case
jonas:j2eeType=JVM,name=jonas,J2EEServer=jonas) has an attribute called
allThreadsCount (The number of active threads in the JVM).

We'll now output this information on different mediums.
On the console
We know that:
- We'll be targeting only one server
- The IP address of the targeted server is 129.183.101.109
- The JOnAS Administration interface tells the JRMP MBean connector is on service:jmx:rmi:///jndi/rmi://localhost:1099/jrmpconnector_jonas
- We want a refresh period of 1 second
Therefore, the command to launch is:
java -Djasmine.jmx.url=service:jmx:rmi:///jndi/rmi://129.183.101.109:1099/jrmpconnector_jonas -jar mbean.jar stat -p 1
-name "*:j2eeType=JVM,*" -a allThreadsCountThis displays the following output:
date;time;sname;server;domain;mbean;allThreadsCount
2007/12/21 11:03:22;1198231402118;jonas;jonas;jonas;jonas:j2eeType=JVM,name=jonas,J2EEServer=jonas;125
2007/12/21 11:03:23;1198231403194;jonas;jonas;jonas;jonas:j2eeType=JVM,name=jonas,J2EEServer=jonas;126
2007/12/21 11:03:24;1198231404254;jonas;jonas;jonas;jonas:j2eeType=JVM,name=jonas,J2EEServer=jonas;123
2007/12/21 11:03:25;1198231405313;jonas;jonas;jonas;jonas:j2eeType=JVM,name=jonas,J2EEServer=jonas;130
2007/12/21 11:03:26;1198231406373;jonas;jonas;jonas;jonas:j2eeType=JVM,name=jonas,J2EEServer=jonas;126
[etc]
On that output, you'll notice that:
- The first row of data contains the list of attributes
- All other rows contain the sampled data using the format specified in the first row
On a spreadsheet
Since any spreadsheet software can read comma separated values, it is rather trivial to import data captured by MBeanCmd into a spreadsheet: just copy and paste the console output:
In a graph
The
-graph option can be used to display the sampled data in a graph. The XML DTD of a graph can be accessed by typing:
java -jar mbean.jar help stat
or
java -jar mbean.jar help poll
To display the number of threads in a simple graph, the following
graph.xml file can be used:
<?xml version='1.0' encoding='UTF-8' ?>
<monitor separator=";" timeformat="long" >
<serie-def id="s1">
<name>Number of threads</name>
<x col="time" type="time"/>
<y col="allThreadsCount" type="long"/>
</serie-def>
<graph id="g1">
<title>Number of threads</title>
<serie ref="s1"/>
</graph>
</monitor>
Launching it can be done as follows:
java -Djasmine.jmx.url=service:jmx:rmi:///jndi/rmi://129.183.101.109:1099/jrmpconnector_jonas -jar mbean.jar stat -p 1
-graph graph.xml -name "*:j2eeType=JVM,*" -a allThreadsCountWhich will display the following graph:

Note that you can also display multiple series on one graph.
Mgen: configuration generation tool
mgen tool aims at generating quickly a mbeancmd configuration for
monitoring a whole JOnAS cluster platform in a few steps.
mgen relies on an uniq XML file (mgen-conf.xml) describing the comprehensive JOnAS platform:
1) the 'servers' element gathers the network parameters of the JOnAS instances
2) the 'components' element lists the module to supervise for each JOnAS instance,
tx, sessions, http, axis, slsb, ds, …
3) the 'variables' element describes the application variables reused in the component command
mgen is delivered with the mbeancmd code source in the 'mgen' subdirectory.
Usage: After having filling the mgen-conf.xml with your platform parameters and your
monitoring requirements, just run 'ant'
Note that if your JOnAS platform host several applications, you may have to define several mgen-conf.xml file (one per application), at least for supervizing the application components (servlet,session,...).