http://java.sun.com/developer/technicalArticles/J2SE/jmx.html
JMX technology provides a component-based architecture for developing solutions to monitor and manage your applications, services, and resources. JMX technology is the way to instrument any application or service that was built using Java technology. Hence, the Java platform now provides excellent facilities for creating and managing applications and services. JMX technology should be used for any application and service that benefit from being manageable, as this will increase their value to vendors and clients, by making them easier to install, configure, and maintain. The current version of JMX is 1.2, and the JMX 2.0 update was launched in September 2004. It will update the JMX and JMX Remote APIs to improve existing interfaces, mainly with respect to ease of use.
This article provided a fast track introduction and tutorial to the JMX architcture and its programming model. The sample code provided demonstrates how easy it is to get started developing management and monitoring solutions using JMX technology. The J2SE 5.0 implements the JMX specification—if you use J2SE 5.0, you are ready to start developing using JMX tech
- MBeans: An MBean is a Java object that implements a specific interface. The management interface of an MBean is represented as: (1) valued attributes that can be accessed; (2) operations that can be invoked; (3) notifications that can be emitted; and (4) the constructors. There are four types of MBeans:
- Standard MBeans: The simplest to design and implement. Their management interface is described by their method names.
- Dynamic MBeans: They implement a specific interface, and they expose their management interfaces at runtime for greatest flexibility.
- Open MBean: Dynamic MBeans that rely on basic data types for universal manageability; they are self-describing for user-friendliness.
- Model MBeans: Dynamic MBeans that are fully configurable and self described at runtime. They provide a generic MBean class with default behavior for dynamic instrumentation of resources.
- Notification Model: JMX technology defines a generic notification model based on the Java event model. It lets developers build proactive management solutions. Using notifications, JMX agents and MBeans can send critical information to interested parties such as management applications or other MBeans.
- MBean Metadata Classes: These classes contain the structures to describe all components of an MBean's management interface: its attributes, operations, notification, and constructors. For each of these, the metadata include a name, a description and its particular characteristics (for example, an attribute is readable, writeable, or both; for an operation, the signature of its parameter and return types).
The main components at the agent level are the MBean Server and Agent Services.
- MBean Server: A registry of objects that are exposed to management operations in an agent. Any object registered with the MBean server becomes visible to management applications. However, note that the MBean server only exposes an MBean's management interface and never its direct object reference. Any resources that you want to manage from outside the agent's JVM must be registered as an MBean in the server. The server also provides a standardized interface for accessing MBeans within the same JVM, giving local objects all the benefits of manipulating manageable resources. MBeans can be instantiated and registered by another MBean, the agent itself, or a remote management application through the distributed services. When you register an MBean, you must assign it a unique object name, which is used by the management application to identify the object on which to perform a management operation.
- Agent Services: Objects that can perform management operations on the MBeans registered in the MBean server. By including management intelligence in the agent, JMX helps you build more powerful management solutions. The JMX API defines the following Agent Services available in J2SE 5.0:
- Dynamic Class loader: Through the management applet (m-let) service, retrieves and instantiates new classes and native libraries from an arbitrary network location.
- Monitors: Observe the numerical or string value of an attribute of several MBeans and can notify other objects of several types of changes in the target.
- Timers: Provide a scheduling mechanism based on a one-time alarm-clock notification or on a repeated, periodic notification.
- The relation service: Defines associations between MBeans and enforces the cardinality of the relation based on predefined relation types.
Manager (or Distributed Services) Level
JMX comprises a separate package for each tier of the management architecture. The instrumentation tier will be free, and other tiers can be built from public specifications or reference implementations available under Sun Community Source License. Alternatively, you can purchase commercially supported products.
The Java 2 Platform, Standard Edition 5.0 (J2SE 5.0) supports JMX 1.2 and JMX Remote API 1.0, which is now the official JMX reference implementation (RI). For developers who are running J2SE 1.4, a JMX RI is also available from Sun Microsystems, and can be downloaded free of charge.
Sun Microsystems also provides the Java Dynamic Management Kit (Java DMK). Java DMK 5.1 is the first commercial implementation of the latest versions of the JMX standards, JMX 1.2 and JMX Remote API 1.0. JMDK is an all-in-one product for building secure, interoperable monitoring and management solutions on the J2SE platform, and it is supported on Solaris, Microsoft Windows, and Linux. Several other commercial and open source implementations are available as well. It is worth noting that Tomcat 5.0 implements the JMX specification.
J2SE 5.0 has implemented version 1.2 of the JMX specification and version 1.0 of the JMX Remote API (JSR 160) specification. J2SE 5.0 includes significant monitoring and management features, including:
- JVM instrumentation: The JVM is instrumented for monitoring and management providing built-in, out-of-the-box management capabilities for local and remote access.
- Monitoring and Management APIs: The
java.lang.management
package provides the interface for monitoring and managing the JVM. It provides access to information such as: number of classes loaded and threads running, memory consumption, garbage collection statistics, on-demand deadlock detection, and others. - Management tools such as JConsole, which is a JMX-compliant monitoring tool that comes with J2SE 5.0. It uses JMX instrumentation of the JVM to provide information on performance and resource consumption of applications running on the Java platform.
The core classes for the JMX implementation are provided in the javax.management
package. In addition, the java.lang.management
package provides the mangagement interface for monitoring and management of the JVM as well as the operating system on which the JVM is running.
To enable the JMX agent and configure its operation using jconsole
, your must set some specific system properties when you start the JVM. For local access, set the property com.sun.management.jmxremote
as follows when starting the JVM:
prompt> java -Dcom.sun.management.jmxremote AppName
And, to enable monitoring and management from remote systems, set the property:
com.sun.management.jmxremote.port=portNumber
For more information on setting system properties for JMX, please see Monitoring and Management using JMX.
Using JMX to instrument your applications, services, or devices for manageability is simple. This is because JMX technology shares Java's object model. If you are familiar with Java and its JavaBeans component model, you already know 95% of all you need to know.
As mentioned previously, an MBean is a Java object that follows some standard design patterns and naming conventions. It can represent a device, application, or any resource that needs to be managed. An MBean exposes a management interface or a set of readable and/or writable attributes and a set of invokable operations, along with a self-description. Note that the management interface does not change through the life of an MBean instance.