Contents
The Java Management Extensions (JMX) API is a standard specification—developed through theJava Community Process (JCP) asJSR 3—for managing and monitoring applications and services. It defines a management architecture, design patterns, APIs, and services for building Web-based, distributed, dynamic, and modular solutions to manage Java-enabled resources. The JMX APIs make it possible to add manageability to Java-enabled equipment, from web phones to set-top boxes to network devices and servers. Using JMX technology to manage applications and services increases their value to vendors and clients by making applications easier to install, configure, and maintain. This article provides a fast track technical tutorial to JMX. It discusses JMX and its tiered architecture, the JMX programming model, and code demonstrating how to use JMX to develop management applications. In addition, the article shows how to use a JMX-compliant management tool in the Java 2 Platform, Standard Edition 5.0 (J2SE 5.0), which has implemented version 1.2 of the JMX specification.
Overview of JMX
JMX is native to the Java programming language. As a result, it offers natural, efficient, and lightweight management extensions to Java-based functions. It consists of a set of specifications and development tools for managing Java environments and developing state-of-the-art management solutions for applications and services. It provides Java developers with the means to instrument Java code, create smart Java agents, implement distributed management middleware and managers, and easily integrate these solutions into existing management and monitoring systems. The dynamics of JMX enable you to use it to monitor and manage resources as they are implemented and installed. It can also be used to monitor and manage theJava Virtual Machine (JVM machine). Typical uses of the JMX technology include:
Benefits of JMX The JMX technology enables Java developers to encapsulate resources as Java objects and expose them as management resources in a distributed environment. The JMX specification lists the following benefits to using JMX to build a management infrastructure:
JMX provides a tiered architecture where managed resources and management applications can be integrated in the plug-and-play approach as shown in Figure 1. A given resource is instrumented by one or more Java objects known as Managed Beans (or MBeans), which are registered in a core managed object server known as the MBean server. This server acts as a management agent and can run on most Java-enabled devices. Figure 1: JMX Tiered Architecture As Figure 1 demonstrates, there are three tiers or levels in this architecture: instrumentation, agent, and manager. Instrumentation Level This tier contains MBeans and their manageable resources. It provides a specification for implementing JMX-manageable resources, which can be an application, service, device, or user. A resource is manageable if it is developed in Java (or provides a Java wrapper) and has been instrumented so that it can be managed by JMX-compliant applications. A resource is instrumented by one or more MBeans that are either standard or dynamic. Standard MBeans are Java objects that conform to certain design patterns (for example, they must have a constructor and setter/getter methods). A dynamic MBean conforms to a specific interface that offers more flexibility at runtime. The instrumentation of a resource allows it to be manageable at the agent level; however, note that MBeans do not require knowledge of the JMX agent with which they operate. In other words, any JMX-manageable resource can use any JMX agent that offers the services it requires. The key Components at the instrumentation level are the MBeans, the notification model, and the MBean metadata classes.
Agent Level This tier contains the JMX agents used to expose the MBeans. It provides a specification for implementing agents, which control the resources and make them available to remote management applications. Agents are usually located on the same machine as the resources they manage, but this is not a requirement. The JMX agent consists of an MBean server and a set of services for handling MBeans. Managers access an agent's MBeans and use the provided services through a protocol adaptor or connector. But note that JMX agents do not require knowledge of the remote management applications that use them. The main components at the agent level are the MBean Server and Agent Services.
Manager (or Distributed Services) Level This tier contains the components that enable management applications to communicate with JMX agents. It provides the interfaces for implementing JMX managers, and defines the management interfaces and components that operate on agents. Such components provide an interface for a management application to interact with an agent and its JMX manageable resources through a connector, and also expose a management view of a JMX agent and its MBeans by mapping their semantic meaning into the constructs of a data-rich protocol (such as HTML). 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 underSun Community Source License. Alternatively, you can purchase commercially supported products.
JMX Implementations
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. Severalother commercial and open source implementations are available as well. It is worth noting thatTomcat 5.0 implements the JMX specification.
JMX and J2SE 5.0
J2SE 5.0 has implemented version 1.2 of the JMX specification and version 1.0 of theJMX Remote API (JSR 160) specification. J2SE 5.0 includes significant monitoring and management features, including:
The core classes for the JMX implementation are provided in the To enable the JMX agent and configure its operation using prompt> And, to enable monitoring and management from remote systems, set the property: For more information on setting system properties for JMX, please see Monitoring and Management using JMX.
The JMX Programming Model
Using JMX to instrument your applications, services, or devices for manageability is simple. This is because JMX 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. Sample Application This simple application manages a resource. You will create a simple standard MBean that exposes a String object and an operation. For more JMX examples, please see theJMX Tutorial. The first step is to develop the MBean interface. In this application, the interface is called
Code Sample 1: HelloMBean.java
The next step is to implement the MBean interface. A sample implementation is shown in the following Code Sample.
Code Sample 2: Hello.java
Congratulations! You have created your first MBean. The next step is to test the MBean, by developing a JMX agent in which you register the MBean. A JMX agent is a component in the agent level and acts as a container for the MBean. A sample agent,
Code Sample 3: SimpleAgent.java
The To experiment with this application, do the following:
It is worth noting that local monitoring with
JMX for Remote Management
The MBean server relies on protocol adaptors and connectors to make a JMX agent accessible from management applications outside the agent's JVM. Adaptors provide a view through a specific protocol for all MBeans registered in the MBean server (for example, an HTML adaptor could display an MBean in a Web browser). Connectors provide a manager-side interface that handles the communication between manager and JMX agent. When a remote management application uses this interface, it can connect to a JMX agent transparently through the network regardless of the protocol. JMX technology exports JMX API instrumentation to remote applications by using Remote Method Invocation (RMI). It also defines an optional protocol based directly on TCP sockets called theJMX Messaging Protocol (JMXMP). However, note that this protocol is not supported in J2SE 5.0. The JMX Remote API 1.0 (JSR 160) specification describes how to advertise and find JMX agents using existing discovery and lookup infrastructures. In other words, the specification does not define its own discovery and lookup service. Using existing discovery and lookup services is optional; you can encode the address of your JMX API agents in the form of URLs and make these URLs available to the manager. Using the RMI Connector Code Sample 4 shows an example of using the RMI connector, which is a slight modification of Code Sample 3.
Code Sample 4: SimpleAgent.java
To run this application, do the following:
Using the HTML Adaptor An HTML adaptor is provided by Sun Microsystems and comes with the JMX Reference Implementation (it doesn't come with J2SE 5.0). The HTML adaptor lets you manage MBeans using a Web browser. The adaptor enables you to interact with the agent to view registered MBeans and their attributes. In other words, this adaptor provides a simple yet powerful management tool that lets you:
Code Sample 5 shows the revised
Code Sample 5: SimpleAgent.java
To experiment with this application, do the following:
JMX Related Specifications
The various JSRs that related to JMX follow:
Summary
JMX provides a component-based architecture for developing solutions to monitor and manage your applications, services, and resources. JMX technology isthe 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 theJMX 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 JMX and its programming model. The sample code provided demonstrates how easy it is to get started developing management and monitoring solutions using JMX. The J2SE 5.0 implements the JMX specification—if you use J2SE 5.0, you are ready to start developing using JMX.
Related Information
Acknowledgments
Special thanks to Mandy Chung and Eamonn McManus of Sun Microsystems, whose feedback helped me improve this article. |
Getting Started with Java Management Extensions (JMX): Developing Management and Monitoring Solution
最新推荐文章于 2024-09-19 19:02:04 发布
Getting Started with Java Management Extensions (JMX): Developing Management and Monitoring Solutions