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.


@ThingsExpo Stories
No hype cycles or predictions of a gazillion things here. IoT is here. You get it. You know your business and have great ideas for a business transformation strategy. What comes next? Time to make it happen. In his session at @ThingsExpo, Jay Mason, an Associate Partner of Analytics, IoT & Cybersecurity at M&S Consulting, presented a step-by-step plan to develop your technology implementation strategy. He also discussed the evaluation of communication standards and IoT messaging protocols, data...
In his keynote at 18th Cloud Expo, Andrew Keys, Co-Founder of ConsenSys Enterprise, provided an overview of the evolution of the Internet and the Database and the future of their combination – the Blockchain. Andrew Keys is Co-Founder of ConsenSys Enterprise. He comes to ConsenSys Enterprise with capital markets, technology and entrepreneurial experience. Previously, he worked for UBS investment bank in equities analysis. Later, he was responsible for the creation and distribution of life settle...
Coca-Cola’s Google powered digital signage system lays the groundwork for a more valuable connection between Coke and its customers. Digital signs pair software with high-resolution displays so that a message can be changed instantly based on what the operator wants to communicate or sell. In their Day 3 Keynote at 21st Cloud Expo, Greg Chambers, Global Group Director, Digital Innovation, Coca-Cola, and Vidya Nagarajan, a Senior Product Manager at Google, discussed how from store operations and ...
In his session at 21st Cloud Expo, Raju Shreewastava, founder of Big Data Trunk, provided a fun and simple way to introduce Machine Leaning to anyone and everyone. He solved a machine learning problem and demonstrated an easy way to be able to do machine learning without even coding. Raju Shreewastava is the founder of Big Data Trunk (www.BigDataTrunk.com), a Big Data Training and consulting firm with offices in the United States. He previously led the data warehouse/business intelligence and B...
"IBM is really all in on blockchain. We take a look at sort of the history of blockchain ledger technologies. It started out with bitcoin, Ethereum, and IBM evaluated these particular blockchain technologies and found they were anonymous and permissionless and that many companies were looking for permissioned blockchain," stated René Bostic, Technical VP of the IBM Cloud Unit in North America, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Conventi...
A strange thing is happening along the way to the Internet of Things, namely far too many devices to work with and manage. It has become clear that we'll need much higher efficiency user experiences that can allow us to more easily and scalably work with the thousands of devices that will soon be in each of our lives. Enter the conversational interface revolution, combining bots we can literally talk with, gesture to, and even direct with our thoughts, with embedded artificial intelligence, whic...
BnkToTheFuture.com is the largest online investment platform for investing in FinTech, Bitcoin and Blockchain companies. We believe the future of finance looks very different from the past and we aim to invest and provide trading opportunities for qualifying investors that want to build a portfolio in the sector in compliance with international financial regulations.
Product connectivity goes hand and hand these days with increased use of personal data. New IoT devices are becoming more personalized than ever before. In his session at 22nd Cloud Expo | DXWorld Expo, Nicolas Fierro, CEO of MIMIR Blockchain Solutions, will discuss how in order to protect your data and privacy, IoT applications need to embrace Blockchain technology for a new level of product security never before seen - or needed.
Leading companies, from the Global Fortune 500 to the smallest companies, are adopting hybrid cloud as the path to business advantage. Hybrid cloud depends on cloud services and on-premises infrastructure working in unison. Successful implementations require new levels of data mobility, enabled by an automated and seamless flow across on-premises and cloud resources. In his general session at 21st Cloud Expo, Greg Tevis, an IBM Storage Software Technical Strategist and Customer Solution Architec...
Imagine if you will, a retail floor so densely packed with sensors that they can pick up the movements of insects scurrying across a store aisle. Or a component of a piece of factory equipment so well-instrumented that its digital twin provides resolution down to the micrometer.
When shopping for a new data processing platform for IoT solutions, many development teams want to be able to test-drive options before making a choice. Yet when evaluating an IoT solution, it’s simply not feasible to do so at scale with physical devices. Building a sensor simulator is the next best choice; however, generating a realistic simulation at very high TPS with ease of configurability is a formidable challenge. When dealing with multiple application or transport protocols, you would be...
Nordstrom is transforming the way that they do business and the cloud is the key to enabling speed and hyper personalized customer experiences. In his session at 21st Cloud Expo, Ken Schow, VP of Engineering at Nordstrom, discussed some of the key learnings and common pitfalls of large enterprises moving to the cloud. This includes strategies around choosing a cloud provider(s), architecture, and lessons learned. In addition, he covered some of the best practices for structured team migration an...
Smart cities have the potential to change our lives at so many levels for citizens: less pollution, reduced parking obstacles, better health, education and more energy savings. Real-time data streaming and the Internet of Things (IoT) possess the power to turn this vision into a reality. However, most organizations today are building their data infrastructure to focus solely on addressing immediate business needs vs. a platform capable of quickly adapting emerging technologies to address future ...
We are given a desktop platform with Java 8 or Java 9 installed and seek to find a way to deploy high-performance Java applications that use Java 3D and/or Jogl without having to run an installer. We are subject to the constraint that the applications be signed and deployed so that they can be run in a trusted environment (i.e., outside of the sandbox). Further, we seek to do this in a way that does not depend on bundling a JRE with our applications, as this makes downloads and installations rat...
Widespread fragmentation is stalling the growth of the IIoT and making it difficult for partners to work together. The number of software platforms, apps, hardware and connectivity standards is creating paralysis among businesses that are afraid of being locked into a solution. EdgeX Foundry is unifying the community around a common IoT edge framework and an ecosystem of interoperable components.
DX World EXPO, LLC, a Lighthouse Point, Florida-based startup trade show producer and the creator of "DXWorldEXPO® - Digital Transformation Conference & Expo" has announced its executive management team. The team is headed by Levent Selamoglu, who has been named CEO. "Now is the time for a truly global DX event, to bring together the leading minds from the technology world in a conversation about Digital Transformation," he said in making the announcement.
In this strange new world where more and more power is drawn from business technology, companies are effectively straddling two paths on the road to innovation and transformation into digital enterprises. The first path is the heritage trail – with “legacy” technology forming the background. Here, extant technologies are transformed by core IT teams to provide more API-driven approaches. Legacy systems can restrict companies that are transitioning into digital enterprises. To truly become a lead...
Digital Transformation (DX) is not a "one-size-fits all" strategy. Each organization needs to develop its own unique, long-term DX plan. It must do so by realizing that we now live in a data-driven age, and that technologies such as Cloud Computing, Big Data, the IoT, Cognitive Computing, and Blockchain are only tools. In her general session at 21st Cloud Expo, Rebecca Wanta explained how the strategy must focus on DX and include a commitment from top management to create great IT jobs, monitor ...
"Cloud Academy is an enterprise training platform for the cloud, specifically public clouds. We offer guided learning experiences on AWS, Azure, Google Cloud and all the surrounding methodologies and technologies that you need to know and your teams need to know in order to leverage the full benefits of the cloud," explained Alex Brower, VP of Marketing at Cloud Academy, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clar...
The IoT Will Grow: In what might be the most obvious prediction of the decade, the IoT will continue to expand next year, with more and more devices coming online every single day. What isn’t so obvious about this prediction: where that growth will occur. The retail, healthcare, and industrial/supply chain industries will likely see the greatest growth. Forrester Research has predicted the IoT will become “the backbone” of customer value as it continues to grow. It is no surprise that retail is ...