Welcome!

Weblogic Authors: Yeshim Deniz, Elizabeth White, Michael Meiner, Michael Bushong, Avi Rosenthal

Related Topics: Weblogic

Weblogic: Article

Exploring WebLogic JMX Part 2

Exploring WebLogic JMX Part 2

The Java Management Extensions (JMX) API provides a standard way of adding management capabilities to Java applications. BEA WebLogic 6.1 provides a full implementation of the JMX 1.0 specification, with all of its management features based on the JMX standard. As a result, the management capabilities in WLS are open and extensible, which makes it easy to build specialized management utilities for applications deployed on WLS.

In Part 1 of this series (WLDJ, Vol. 1, issue 4), we saw how JMX represents manageable resources as Managed Beans (MBeans), and provides a set of APIs for management applications to access those resources. In this article, we'll look at some of the details of how WebLogic Server 6.1 is instrumented using JMX, and how the JMX services offered by WebLogic can be used to monitor deployed applications. Using WLS JMX, we will gather runtime information from the application as it services client requests using the Java Pet Store example.

Before looking at the Pet Store example, though, we'll examine a few of the features of WebLogic JMX that simplify the creation of management applications.

Accessing MBeans in WebLogic Server
Management applications access the instrumented resources of a system to perform tasks such as monitoring or administration. These applications may take the form of graphical resource monitors, Web-based administration consoles, report-generating utilities, or other similar applications.

JMX allows the management interface of an application or resource to be exposed as a set of MBeans. These MBeans can then be accessed by management applications through the JMX agent level, whose main component is the MBeanServer.

WebLogic JMX is implemented in a way that simplifies the creation of management applications by making it easier to access MBeans and invoke methods on them. To gain access to MBeans, WebLogic JMX provides an MBeanHome - an augmentation of the standard MBeanServer that provides direct access to all the WebLogic Server predefined MBeans through a simplified API. The standard MBeanServer, by contrast, can provide only indirect access to the MBeans of the system. Access to MBeans is further simplified through WebLogic Server's use of JNDI and RMI in its JMX distribution level - providing direct access to the MBeans for both remote and local clients. Finally, all of the predefined WebLogic MBeans are implemented as standard MBeans (as opposed to dynamic and model MBeans, described in Part 1), which allows clients to make direct use of interfaces, instead of invoking MBean methods through reflection.

Together, these enhancements within the WebLogic Server JMX implementation simplify the creation of management applications that are specifically targeted for WebLogic Server. Applications that are meant to be portable to other application servers can still be written using the standard JMX APIs.

To observe the difference between the standard approach to accessing MBeans and the simplified approach using the WLS specific features, we'll look at two code samples, one that doesn't make use of these features and one that does. Listing 1 shows how to use standard JMX protocols to access MBeans in WebLogic Server. In particular, this example shows how to look at the "ServerRuntime" MBean, an MBean that is provided by WebLogic Server to supply overall information about the runtime system. After obtaining a reference to the MBeanServer, a JMX ObjectName instance is created using the full MBean name. The full name of this MBean is:

"petstore:Location=petstoreServer,Name=petstore Server,Type=ServerRuntime"

Before the colon, we see the domain name; additional attribute/value pairs identify the MBean from others deployed on that domain. Once the ObjectName is created, it is passed to the MBeanServer, along with the name of the method to be invoked on the bean. The method "getWeblogicVersion" is called through the "invoke" method defined on the MBeanServer, which uses reflection to call the corresponding method on the ServerRuntime MBean - the client never directly accesses the MBean itself.

In contrast, Listing 2 shows how this process works using the simplified WLS interfaces. In this case, a reference to the MBeanHome is obtained. From there, we can get a direct reference to the ServerRuntime MBean using a much simpler lookup name than the full ObjectName of the bean (we only need to supply the "Name" and "Type" - the MBeanHome is already aware of the domain and server that it's deployed on). The ServerRuntime MBean can be sent messages just like any regular Java object; there's no need to use the reflective "invoke" protocol required by the MBeanServer.

There are several advantages to the WebLogic approach to looking up and using MBeans. The code is simpler - using direct invocation rather than reflection makes the code easier to write and understand. Moreover, using the interfaces directly means that type checking can occur - many coding errors will be caught at compilation, while the "reflective" style is more prone to error.

In addition to providing an augmented and simplified API for accessing MBeans, WebLogic provides a large number of MBeans so that applications deployed on the server are "preinstrumented" and ready to be configured and monitored by management applications. Consequently, users of WebLogic JMX will generally find that they can create management applications based solely on the MBeans provided by WebLogic Server - only less frequently will users have to create their own MBeans to add additional instrumentation.

To get an appreciation of the amount of instrumentation that WLS provides with a deployed application, we can use MBeanHome to count the number of MBeans made available. Listing 3 shows how the MBeanHome can be queried for information about the MBeans available in the system. Running the code with the default "clean" domain (mydomain) and comparing this with the number of MBeans made available for the domain that has the Pet Store deployed in it shows that 577 MBeans are in the system for a clean WebLogic Server installation, but that 697 MBeans are in the system for the domain running the Pet Store. These 120 additional MBeans are beans used to configure the resources required by the Pet Store application (the JDBC connection pools, for example), and beans that can be used to monitor the state of the resources and components that make up the Pet Store.

Our main purpose is to show how these additional MBeans, created by WebLogic Server for deployed applications, can be used to carry out some simple runtime monitoring of the Pet Store. However, you may be wondering, "What are all these hundreds of MBeans in the default domain doing?"

WebLogic Server MBeans
Many of the MBeans that live within the server are there to provide an API for configuring the server itself. All of the configurable aspects of the WebLogic Server are represented as MBeans - from security, connection pools, and clustering, to the servers, and domains themselves. To get an idea of the scope of what can be configured, you only have to look at the WebLogic Administration Console. Virtually every element configurable through the console is also available through an MBean. Providing this layer means that all of the manual configuration that is normally done through the console can also be done programmatically, and that other utilities can provide the same functions as the console.

In addition to the configuration information represented as MBeans, a large amount of transient runtime data is also available in MBean form. This includes information about open servlet sessions, active JDBC connections, JTS transactions, pooled EJBs, JMS messages, and so on.

To provide access to this configuration and transient runtime data, WebLogic Server provides three types of MBeans: Administration, Configuration, and Runtime.

Administration and Configuration MBeans
Administration and Configuration MBeans represent the configuration data found in the config.xml file and accessible through the Administration Console. Administration MBeans represent this data in its persistent form - any changes to these MBeans will be saved to the config.xml file. Configuration MBeans represent this data in its active form; changes made to these beans will affect the running system, but won't be saved to the config.xml file. The distinction between Administration and Configuration MBeans gives management applications the option of making either temporary changes to the configuration of the running system (through the Configuration MBeans), or permanent changes (through the Administration MBeans).

Administration and Configuration MBeans implement the same interfaces - they're differentiated based on their ObjectName and in how they can be accessed. While Configuration MBeans are obtained from the MBeanHome as shown in Listing 2, Administration MBeans must be obtained from a distinct Administration MBeanHome. Each WebLogic Server instance has its own MBeanHome, while the Administration MBeanHome resides only on the administration server and is shared across a domain.

Runtime MBeans
Runtime MBeans provide information about the state of deployed components (EJBs, servlets, etc.), resources (JDBC connection pools, sockets, etc.), and the server.

The large numbers of MBeans in the "empty" domain can be attributed to the one Web application that is deployed to it - the Administration Console. The vast majority of the MBeans deployed in the "default" domain are actually MBeans associated with the Administration Console. Over 400 of the 577 MBeans that were counted in the default domain are associated with the console. These MBeans are runtime, administration, and configuration beans for the servlets and other components that make up the console, or additional MBeans created by the console to help it more easily administer the server.

Why Runtime Monitoring?
Many of the MBeans provided by WebLogic Server are involved with tracking the evolving runtime state of the system and the application and resource components that reside in it. This runtime information can be very useful for application developers and for those administering already deployed systems.

Building runtime monitoring into a system is difficult - it often takes the clumsy form of "System.out.println" statements scattered throughout the code. Sometimes the monitoring can interfere with the running code, and in some cases what needs to be monitored is inaccessible - information that is hidden within a resource that the application is accessing.

The runtime monitoring provided by WebLogic JMX provides a better alternative to putting monitoring code directly into an application - and since the monitoring is built into the application server, it can track resource-related state that may be difficult to access from within the application code.

Runtime MBeans allow monitoring facilities to be built around an already existing and deployed application - without taking down the server or affecting the application in any way.

As an example, in the next section we will show you how to obtain some runtime statistics about the transactional behavior of some of the components within the Java Pet Store.

Runtime Monitoring of the Java Pet Store
The Java Pet Store application is the canonical J2EE example application. The Pet Store uses EJBs, JSPs, JMS, and other Enterprise Java features, and is built using an application architecture based on the J2EE blueprints described by Sun. It's a classic "online shopping" application based around the well-known "shopping-cart" paradigm for tracking purchases as users browse through an online merchandise inventory.

A version of the Java Pet Store is provided with the WebLogic 6.1 installation - a fully configured domain for the Pet Store is found in the "config" folder under the WebLogic home directory. All of the discussion and examples here use this Pet Store example, unmodified. The Pet Store included in the WebLogic 6.1 install is slightly modified from Version 1.1.2 of Sun's Java Pet Store.

Transaction Monitoring Example
For our runtime-monitoring example using WebLogic JMX, our goal will be to find how many JTS transactions are committed, rolled back, or timed-out against the "Shopping Cart" component in a typical user interaction with the Pet Store. We'll do this with a small Java class CartTransactionTracker that connects to the running server remotely.

In an EJB-based application, transactional overhead can be a significant performance issue, so this kind of monitoring is quite relevant. By extending this example to the other components in the system, it's possible to detect the components that are the most "transaction intensive."

There are actually several ways to get information about the transaction load from WebLogic's JMX services. The method that we'll use involves looking at several Runtime MBeans that are associated with deployed EJB components.

Information about the transactions committed, rolled back, or timed out against the shopping cart EJB can be obtained from the EJBTransaction Runtime MBean associated with it. Each EJB deployed in WebLogic has the EJBTransactionRuntime MBean that carries this information.

To look up the EJBTransactionRuntime for a particular bean, there are, again, several methods. Every MBean in the system can be looked up directly based on its full name. However, WebLogic Server provides a more intuitive system, by which MBeans can be accessed from other MBeans related to them.

A good entry point to the MBeans associated with a particular EJB is provided by the EJBComponentRuntime. The EJBComponentRuntime of an ejb-jar is one way to access the MBeans for all the EJBs deployed in that archive. From EJBComponentRuntime, we obtain a reference to the MBean associated with the particular bean - an EJBRuntime. The EJBRuntime maintains a reference to the EJBTransactionRuntime, which (as previously mentioned) tracks transaction information for a particular EJB. The relationship between these Runtime MBeans is shown in Figure 1.

In our example we want to find out about the transactions associated with the Shopping Cart EJB. This bean, whose EJB name is "TheCart", consists of a bean-class, ShoppingCartEJB; a remote interface, ShoppingCart; and a home interface, ShoppingCartHome. It is deployed in the ejb-jar called "shoppingcartEJB.jar" within the "petstore.ear" enterprise archive.

To get to the EJBRuntime MBean associated with the Shopping Cart, we'll look up the EJBComponentRuntime for the "shopping cart.jar". WebLogic's naming convention for EJBComponentRuntime MBeans is straightforward - the ejb-jar name, followed by an underscore, followed by the EAR name; in this case, "shoppingcartEJB_petstore". Listing 4 shows the code required to obtain the MBean for this ejb-jar.

The shoppingcartEJB.jar file contains two EJBs - the Shopping Cart entity bean, and the Catalog session bean. To find the Shopping Cart, we can ask the EJBComponentRuntime MBean for all of its beans, and select the bean with the matching EJB Name. Listing 5 looks at the EJBRuntime MBeans returned from the EJBComponent Runtime for the MBean with the ejb-name "TheCart".

Finally, we can obtain information about the transactions from the EJBTransactionRuntime that is available from the EJBRuntimeMBean. Listing 6 briefly shows how this can be done.

Combining these steps - looking up the MBeans that represent the JAR, the individual EJB, and the transactions for the bean - yields a simple client that reports the transactional activity of the Shopping Cart EJB. Running this after single-user tests can provide some insight into bean behavior. Extending this across other EJBs in the system can reveal which components do the most transactional work, and can, in stress tests, detect points of failure.

Possible Extensions
What other information could we have obtained from the various EJB Runtime MBeans that we accessed in this example? Additional information includes caching, pooling, and locking data (all available on the bean type-specific subinterfaces of the EJBRuntimeMBean).

In this example, a simple remote client was used to log the results each time the client was run. Other implementation possibilities include:

  • Having the program implement the javax.management.NotificationListener interface, and publish Transaction data as it becomes available. WebLogic JMX supports both remote listeners and listeners running inside the server.
  • Using the various MBean monitors provided with JMX, we could set the logging options to record when the number of transactions rolled-back or timed-out reach certain threshold values.
  • Creating a new MBean that ties together the relevant monitoring information for the Pet Store application. This PetStoreRuntime MBean would access the other standard MBeans we discussed, but tie them together so that they are more specifically tailored for the particular application. The benefit of extending WebLogic Server Administration by adding new MBeans is that any generic JMX monitoring tool could then access this customized management interface. However, user-defined MBeans must be accessed through the MBeanServer, and not the WLS MBeanHome.

Other possibilities include extending the monitoring to cover servlet runtime behavior and JDBC connection pools.

Conclusion
Many enterprise-critical applications have been deployed on the J2EE platform - a key requirement of such applications is the availability of flexible and useful management utilities.

WebLogic 6.1 and its JMX-based administration facilities provide several enhancements over the standard JMX API that make it easy to build simple management applications while still allowing users to create standard applications that can run against any JMX implementation. These can be used to monitor existing applications without affecting the application code, and can be particularly helpful in locating problem areas or generating data to help in performance tuning.

In addition to providing enhancements to the JMX distribution and access levels, WebLogic JMX provides a full instrumentation of the WebLogic Server. Administration, configuration, and runtime data can be easily accessed through simple applications running inside or outside the server.

Finally, WebLogic's management capabilities are extensible, which means that any custom interfaces built using JMX can be accessed by JMX-compliant management applications.

By taking advantage of the APIs and MBeans provided by WebLogic Server, developers can create applications that are easier to monitor and administer, and can also create sophisticated management tools for those applications.

References

More Stories By Dan MacKinnon

About 7 years ago I wrote these two articles for the now defunct "WebLogic Developers Journal." They have now shown up on 'ulitzer'. They are now horribly out of date - please ignore them! :) Thanks, -- Dan

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


IoT & Smart Cities Stories
The hierarchical architecture that distributes "compute" within the network specially at the edge can enable new services by harnessing emerging technologies. But Edge-Compute comes at increased cost that needs to be managed and potentially augmented by creative architecture solutions as there will always a catching-up with the capacity demands. Processing power in smartphones has enhanced YoY and there is increasingly spare compute capacity that can be potentially pooled. Uber has successfully ...
The deluge of IoT sensor data collected from connected devices and the powerful AI required to make that data actionable are giving rise to a hybrid ecosystem in which cloud, on-prem and edge processes become interweaved. Attendees will learn how emerging composable infrastructure solutions deliver the adaptive architecture needed to manage this new data reality. Machine learning algorithms can better anticipate data storms and automate resources to support surges, including fully scalable GPU-c...
We are seeing a major migration of enterprises applications to the cloud. As cloud and business use of real time applications accelerate, legacy networks are no longer able to architecturally support cloud adoption and deliver the performance and security required by highly distributed enterprises. These outdated solutions have become more costly and complicated to implement, install, manage, and maintain.SD-WAN offers unlimited capabilities for accessing the benefits of the cloud and Internet. ...
Dion Hinchcliffe is an internationally recognized digital expert, bestselling book author, frequent keynote speaker, analyst, futurist, and transformation expert based in Washington, DC. He is currently Chief Strategy Officer at the industry-leading digital strategy and online community solutions firm, 7Summits.
As IoT continues to increase momentum, so does the associated risk. Secure Device Lifecycle Management (DLM) is ranked as one of the most important technology areas of IoT. Driving this trend is the realization that secure support for IoT devices provides companies the ability to deliver high-quality, reliable, secure offerings faster, create new revenue streams, and reduce support costs, all while building a competitive advantage in their markets. In this session, we will use customer use cases...
Machine learning has taken residence at our cities' cores and now we can finally have "smart cities." Cities are a collection of buildings made to provide the structure and safety necessary for people to function, create and survive. Buildings are a pool of ever-changing performance data from large automated systems such as heating and cooling to the people that live and work within them. Through machine learning, buildings can optimize performance, reduce costs, and improve occupant comfort by ...
René Bostic is the Technical VP of the IBM Cloud Unit in North America. Enjoying her career with IBM during the modern millennial technological era, she is an expert in cloud computing, DevOps and emerging cloud technologies such as Blockchain. Her strengths and core competencies include a proven record of accomplishments in consensus building at all levels to assess, plan, and implement enterprise and cloud computing solutions. René is a member of the Society of Women Engineers (SWE) and a m...
With 10 simultaneous tracks, keynotes, general sessions and targeted breakout classes, @CloudEXPO and DXWorldEXPO are two of the most important technology events of the year. Since its launch over eight years ago, @CloudEXPO and DXWorldEXPO have presented a rock star faculty as well as showcased hundreds of sponsors and exhibitors! In this blog post, we provide 7 tips on how, as part of our world-class faculty, you can deliver one of the most popular sessions at our events. But before reading...
Poor data quality and analytics drive down business value. In fact, Gartner estimated that the average financial impact of poor data quality on organizations is $9.7 million per year. But bad data is much more than a cost center. By eroding trust in information, analytics and the business decisions based on these, it is a serious impediment to digital transformation.
Charles Araujo is an industry analyst, internationally recognized authority on the Digital Enterprise and author of The Quantum Age of IT: Why Everything You Know About IT is About to Change. As Principal Analyst with Intellyx, he writes, speaks and advises organizations on how to navigate through this time of disruption. He is also the founder of The Institute for Digital Transformation and a sought after keynote speaker. He has been a regular contributor to both InformationWeek and CIO Insight...