Getting Started with JMX Monitoring in NetBeans IDE 5.0
Jean-Francois Denise ( ), JMX team
The NetBeans JMX Module integrates JMX technology right into your workflow in the NetBeans IDE. This module allows you to quickly develop management applications, add management to exisiting applications, develop manager applications, and monitor the state of the Virtual Machine. The module is available for NetBeans IDE versions 4.0 and higher. You can install the module by choosing Tools > Update Center and downloading the module from the NetBeans Update Center.
Note: This tutorial works with IDE versions 4.0 through 5.5.1. A version of this tutorial targeted toward NetBeans IDE 6.0 is planned to be finished soon.
This getting started guide presents the features of the module:
Wizards to help you develop JMX MBeans, Agents, and Managers. A set of actions to update exisiting MBeans (add attributes, operations, implement the MBeanRegistration interface, etc.)
MBean generation from an existing Java Class.
An action to register MBeans and Java objects in a JMX Agent.
Generation of JUnit tests that are ready to test (new or existing) MBean attributes and operations. The ability to launch the JDK 1.5 management console (JConsole). Integration with Java project. You can Run and Debug your application using JConsole. A sample application based on the Anagram game that shows you how to add JMX power to your application
A wizard to generate a JDK 1.5 management properties file, that allows you to launch a secure manageable JVM. Online help system that includes the following:
Architectural information on JMX Detailed information on how to use the wizards/actions How to use the module's features in a Web Application project
Tutorials accessible from the netbeans.org site.
Accessing the Wizards
You can access the wizards by choosing File > New File (Ctrl-N) and selecting one of the following templates from the Management category:
JMX Agent. A JMX agent is any application that registers MBeans with an MBeanServer. JMX MBean. An MBean can represent a device, an application, or any resource that needs to be managed. MBeans expose a management interface: a set of readable and/or writable attributes and a set of invokable operations, along with a self-description. The management interface does not change throughout the life of an MBean instance. MBeans can also emit notifications when certain defined events occur. JMX MBean JUnit Test. The JUnit test for any existing MBean. Management Configuration File. A standard properties file that registers configuration properties for your JMX management. JMX Manager. A JMX Manager is any application that connects to a remote JMX Agent.
Updating MBeans and Adding MBeans to a JMX Agent
To update an MBean, select the MBean class in the Projects tree then access the Management contextual menu by right-clicking on the node or via the top level management menu.
To add an MBean to a previously generated JMX Agent, select the Agent class in the Projects tree then access the Management contextual menu by right-clicking on node or via the top level management menu.
Implementing and Executing Manageable Applications
Typically, the work flow of implementing and executing manageable applications is as follows:
Generate your MBeans. Instrument your MBeans Instrument your unit test logic. Generate a JMX Agent (which is either runnable or not). Runnable agents are used to develop management agents. Non-runnable agents are embedded in a runnable application (see the sample application for an example of an embedded agent). Run and/or debug the project with JConsole using the new project utilities located in the toolbar.

For advanced users: If you want to test your application with remote management enabled, you can use the remote management utilities (located in Run > Remote Management menu). Use the Management Properties File wizard and the generated file when launching the action.
Launching JConsole from NetBeans
This is really easy. Just click this nice icon:
Running the Sample Application
The JMX module includes a sample application with JMX monitoring built into it.
Choose File > New Project. In Samples, select the Management category. Select Anagram Game Managed with JMX project.

Once your project is created, Run it with JConsole. The Anagram game is displayed, as well as the JConsole window.

In the JConsole window, go to the MBeans tab:
Select the AnagramsStats MBean. Select the Notifications tab. Subscribe to notifications. Select the Attributes tab. Double click on the LastThinkingTime attribute value to plot it.
In the Anagrams window, solve the first anagram. Notice that the attributes are updated and that the JConsole window received a notification.


What Next?
This document has provided a quick introduction to the JMX module for the NetBeans IDE. You can get more information about the JMX module by completing the
JMX Module Tutorial.