Getting Started with JMX Monitoring in NetBeans IDE
By
and
,
JMX Engineering 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.
This document has been updated for the JMX Wizard module version 3.0,
for NetBeans IDE 6.5 and newer, and running on top of
JDK 5 or JDK 6. You can download the JMX module from the Update Center.
Note:
This document is a short and quick introduction to the JMX module for NetBeans IDE.
For more detailed information, complete the JMX Module Tutorial
Adding JMX Instrumentation to a Java Application.
This getting started document gives you an overview of the JMX module features:
Wizards to create JMX MBeans and Managers.
Actions to update exisiting MBeans by adding attributes and operations,
implementing the MBeanRegistration interface, or implementing
the NotificationEmitter interface.
MBean generation from an existing Java Class.
Action to register MBeans into the Java Platform MBean Server.
Ability to launch the Java Platform management console (JConsole).
Ability to Run and Debug your application using
JConsole.
Sample application based on the Anagram game that shows you how to
add JMX power to your application.
Wizard to generate a management properties file, that
allows you to launch a secure manageable JVM.
Note. NetBeans IDE 6.9 requires Java Development Kit (JDK) 6.
To install the JMX and JConsole plugins, choose Tools > Plugins and download the module from the NetBeans Update Center.
This tutorial requires the JDK 5 or higher version of the Java Platform.
The steps detailed below have been performed with JDK 6.
Accessing the JMX Wizards
After you have installed the JMX plugin and your project is open, you can access the JMX wizard by choose File > New File (Ctrl-N) and selecting the JMX category.
You can then choose among the following:
Management Configuration File. A standard Java properties file to
store your configuration for your JMX management, in particular for remote
connection and security.
Several types of JMX MBeans. 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 MBeans need to be registered into an MBean Server.
JMX Manager. A JMX Manager is any application that connects to a
remote JMX MBean Server.
Updating MBeans
You can add attributes and operations to your MBeans with the JMX contextual
menu actions, which will popup a dialog box.
You can also have your MBeans implement the NotificationEmitter interface.
To update an MBean, either select the MBean class Java file in the Project tree and access
the JMX popup menu by right-clicking on the node,
or simply right-click in the editor's window where your MBean class Java file
is opened and access the JMX popup menu.
To remotely connect to your MBeans and manage your application, your MBeans
need to be registered into an MBean Server.
An MBean Server is the main central piece of the JMX technology. It keeps reference
of all MBean registered into it, can send notifications of new MBean registration or
deletion, and can accept remote connections to expose attributes and operations
of its registered MBeans. If you are not familiar with MBean Server role,
read the
javax.management.MBeanServer API documentation.
Starting with JDK 5, the Java Platform provides a default
MBean Server, called the Platform MBean Server.
It enables you to monitor the JVM, but you can also use it to register your own MBeans into it.
For details on the Java Platform MBean Server, read the
java.lang.management.ManagementFactory
API documentation.
Depending on its logic, determine where in your application code you want
your MBeans to be registered, typically in the initialization phase of your Main
class. Right-Click in your editor's window at the location where you want the
MBean's registration code to be generated,
select the JMX submenu and then the
"Generate MBean Registration..." action.
Implementing and Executing Manageable Applications
Typically, the work flow of implementing and executing manageable applications
is as follows:
Generate your MBeans.
Add implementation to your MBeans
Generate MBean's registration code.
Run or debug your project with JConsole.
Use the following JConsole buttons in the toolbar:
These actions are also accessible from the main menu by choosing Debug >
Run/Debug Main Project with Monitoring and Management.
Launching JConsole from NetBeans
JConsole is a JMX compliant graphical tool for monitoring a Java virtual machine.
It can monitor both local and remote JVMs.
It can also monitor and manage JMX applications, as shown with the Anagram Game in the next section Running the Sample Application.
JConsole is part of the Java Platform since JDK 5, and can be used independently
from NetBeans. For details, refer to the
jconsole man page and to the
Using JConsole document.
Launching JConsole is really easy. Just click this nice icon:
You can also choose Debug > Start JConsole from the main menu.
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 JMX category.
Select the Anagram Game Managed with JMX project.
Click Next. There is no need to change the supplied default project name or
location values. Make sure the Set as Main Project checkbox is selected and click Finish.
Once your project is created, and set as the Main Project,
Run it with JConsole by clicking the
"Run Main Project with Monitoring and Management" JConsole button.
Clicking this button launches and displays the Anagram Game:
The JConsole window is also displayed.
In the JConsole window, select the MBeans tab and in the tree layout
on the left open down all nodes under com.toy.anagrams.mbeans
as shown below:
Select the Notifications node and click on the Subscribe button at the
bottom so that JConsole will receive a new notification each time an anagram is solved.
Now go to the Anagrams Game window, and solve the first three or four anagrams
(The answers are in the WordLibrary class, but here they are:
abstraction, ambiguous, arithmetic, backslash, ...)
Go back to JConsole, and notice that it received the four notifications.
Click on the Attributes node and notice the attributes values are updated:
This document was a short and quick introduction to the JMX module for NetBeans IDE.
For more detailed information, see the following JMX module tutorial: