Getting Started with JMX Monitoring in NetBeans IDE

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 existing 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 6 or JDK 7. 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:

Content on this page applies to NetBeans IDE 7.2, 7.3, 7.4 and 8.0
  • 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.
  • Online help.
  • Tutorials accessible from the netbeans.org site.

Prerequisites

This tutorial assumes you have some basic knowledge of, or programming experience with, the following technologies.

You will also benefit from having some knowledge on Monitoring and Management for the Java Platform

Software Needed for the Tutorial

For this tutorial you need to have the following software installed on your computer:

Software or Resource Version Required
NetBeans IDE 7.2, 7.3, 7.4, 8.0, Java bundle
Java Development Kit (JDK) version 7 or 8
JMX plugin Available from NetBeans Update Center
JConsole plugin Available from NetBeans Update Center

To install the JMX and JConsole plugins, choose Tools > Plugins and download the modules from the NetBeans Update Center.

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.
    screenshot of JMX New File Wizards

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.

These actions are demonstrated in Exercise 3 of the Adding JMX Instrumentation to a Java Application tutorial.

Registering MBeans

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.

This action is demonstrated in Exercise 5 of the Adding JMX Instrumentation to a Java Application tutorial.

Implementing and Executing Manageable Applications

JConsole is a JMX-compliant graphical tool for monitoring a Java virtual machine. JConsole can monitor both local and remote JVMs and can be used to monitor and manage JMX applications.

Typically, the work flow of implementing and executing manageable applications is as follows:

  1. Generate your MBeans.
  2. Add implementation to your MBeans
  3. Generate MBean's registration code.
  4. Run or debug your project with JConsole.

After you install the JMX and JConsole plugins you will see that the following buttons are added to the toolbar. The actions are also accessible under the Debug menu item in the main menu.

Button Description
Run Main Project with Monitoring and Management button in the toolbar Run Main Project with Monitoring and Management
Debug Main Project with Monitoring and Management button in the toolbar Debug Main Project with Monitoring and Management
Start JConsole Management Console button in the toolbar Start JConsole Management Console

Note. JConsole is part of the Java Platform and can be used independently from the IDE. For details, refer to the following resources.

Running the Sample Application

The JMX module includes a sample application with JMX monitoring built into it.

  1. Choose File > New Project.
  2. In Samples, select the JMX category.
  3. Select the Anagram Game Managed with JMX project.
    screenshot of Anagram Game Managed with JMX project in New Project wizard
  4. Click Next. There is no need to change the supplied default project name or location values. Confirm that the Set as Main Project checkbox is selected. Click Finish.

    Notes. The IDE might prompt you to install the JUnit libraries if you did not install the JUnit plugin previously. You can click Resolve in the Resolve Resource Problems dialog box to launch the Installer to install the JUnit plugin. Alternatively, you can install the JUnit plugin in the Plugins manager.

  5. 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.

    Notes. You might see a Connection Failed warning in the Java Monitoring & Management Console when the console attempts to connect to the Anagram Game process. For this tutorial you can click Insecure when you are prompted to authorize the connection.

    Clicking this button launches and displays the Anagram Game:

    Anagram Game

    The JConsole window is also displayed.

  6. In the JConsole window, select the MBeans tab and in the tree layout on the left open down all nodes under anagrams.toy.com as shown below.
    screenshot of JConsole window
  7. 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.
  8. 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, ...)
  9. Go back to JConsole, and notice that it received the four notifications.
  10. Click on the Attributes node and notice the attributes values are updated:
    screenshot of JConsole window showing updated values

See Also

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:

get support for the NetBeans

Support


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo