Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Remotely monitor Tomcat clusters using MC4J

Add the power of JMX to Tomcat

  • Print
  • Feedback

J2SE 5.0's monitoring and management support is comprehensive, with remote monitoring capabilities for the Java platform and for applications that run on it. Included in J2SE 5.0 is Java Management Extensions (JMX) remote monitoring, a new addition to the list of monitoring capabilities on a JVM. Java Specification Request 160 is the specification for JMX remote monitoring. It focuses on the mechanism for remote access by building a remote client API for a JMX-based agent.

Tomcat 5.5 is designed to leverage J2SE 5.0's built-in JMX capabilities. Version 5.5 (which was branched based on Tomcat 5.0.27) implements the latest Servlet (2.4) and JavaServer Pages (2.0) specifications and is the result of an extensive redesign and refactoring of the Tomcat server architecture. It proves more stable and improves upon Tomcat 4.x with enhanced performance, scalability and reliability, JMX monitoring, integrated session clustering, and application deployment.

With the latest version of Tomcat and J2SE 5.0's JMX capabilities, we can make the servlet container's attributes and methods available via JMX while simultaneously reducing the complexity of JMX-related code. In this article, I discuss how to launch the Tomcat servlet container with remote JMX monitoring enabled. We also look at a sample Web application that runs in a Tomcat cluster with session replication turned on. And, finally, we use a JMX client to view the details of cluster elements and HTTP sessions. But before we delve into the discussion of remote JMX monitoring, let's look at the components that make up a Tomcat cluster.

Cluster elements

A Tomcat cluster consists of six main components: cluster, membership, sender, receiver, replication valve, and deployer.

Table 1 shows how each component makes the clustering and session replication work in Tomcat.

Table 1. Tomcat cluster elements

Cluster element Class name Description
Cluster org.apache.catalina.cluster.tcp.SimpleTcpCluster Main element in the cluster configuration. Cluster creates the ClusterManager for all the Web contexts that have distributable tags in the web.xml.
Membership org.apache.catalina.cluster.mcast.McastService Cluster membership is established by the Tomcat instances sending IP multicast pings. A multicast broadcast message contains the IP address and the server's TCP listen port. If an instance has not received the message within a given time frame, the member is considered unavailable. The attributes starting with mcastXXX are for the membership multicast ping.
Sender org.apache.catalina.cluster.tcp.ReplicationTransmitter When session replication is requested, a Tomcat instance will use the host and port information and establish a TCP socket. Using this socket, the instance sends over the session information as serialized data. There are three modes of session replication in Tomcat 5.5: asynchronous, synchronous, and pooled.
Receiver org.apache.catalina.cluster.tcp.ReplicationListener This element is responsible for the actual session replication. It listens on a specified IP address and port number for TCP cluster requests.
Replication valve org.apache.catalina.cluster.tcp.ReplicationValve The replication valve parses the HTTP requests and filters the files that do not need to be replicated. We don't want the session replication to trigger for static files such as HTML, JavaScript, Cascading Stylesheets, PDF, and images. We can filter these file types by specifying the list of file extensions that we don't want to replicate across the cluster.
Deployer org.apache.catalina.cluster.deploy.FarmWarDeployer This is a new element added to Tomcat cluster in the later versions of 5.0.x. It can be used for cluster-wide deployment of Web applications.


Fore more details on the clustering elements, refer to Tomcat 5.5's clustering documentation.

Tomcat 5.5 provides several improvements over its predecessors (Tomcat versions 4.1 and 5.0) in terms of clustering, session replication, and server monitoring and manageability. In Tomcat 4, several server components (such as host, engine, and service) could be monitored using MBeans (managed beans). But in Tomcat 5.5, Yoav Shapira, Filip Hanik, and the other Tomcat developers wrote JMX implementations for the cluster elements.

Now that we know the function of each element in a Tomcat cluster, let's look at various JMX client tools used for connecting to a Tomcat server cluster and monitoring the cluster details.

JMX clients

A JMX client is a graphical user interface (client/server or thin client) used to connect to a JMX agent (running on a local or remote machine). An ideal JMX client should have the following features to monitor an application server effectively without incurring any additional overhead:

  • Low overhead on system and network resources
  • The ability to maintain system stability and performance
  • Minimum or no special configuration needed (if some settings must be configured, they should be configured declaratively rather than programmatically)
  • Good reporting features

J2SE 5.0 comes with a JMX client tool called JConsole that can be used to look into the runtime JVM details. Tomcat installation includes a JMX servlet called JMXProxyServlet that can view and update Tomcat MBean attributes. It is a lightweight proxy for viewing and manipulating the MBeans running in a Tomcat container and proves helpful in integrating command line scripts for monitoring and changing Tomcat internals. JMX Query and Set commands can be used to query the MBeans and modify their attributes and operations respectively.

Other than these two tools, several third-party open source JMX client applications are available (links to which are available in Resources):

  • XMOJO
  • jManage
  • MX4J
  • Spring JMX
  • JMX-HTML adaptor
  • MC4J JMX Console

In this article, I discuss how to install and configure MC4J to remotely connect to a Tomcat servlet container and monitor all the MBean components in a server cluster.

JMX remote monitoring and management using MC4J

The MC4J console provides the following capabilities:

  • Tree view of MBeans, their attributes, operations, and notifications
  • Ability to set values on MBean attributes
  • Ability to execute MBeans operations
  • Connections to multiple J2EE application servers
  • Visual graphs of MBean attributes

I used MC4J 1.2 Beta 9 for this article's sample application. To install MC4J, download the executable (MC4J-12b9-Windows.exe) from SourceForge. Double-click on the exe file and select JDK Home and the MC4J installation directory (c:\dev\tools in the sample setup) when prompted during the installation process.

Set system properties for JMX

You must specify some system properties to see the remote JMX monitoring in action. These properties are specified in a properties file called management.properties located in the JAVA_HOME/lib/management directory. Table 2 shows the properties that must be set for JMX monitoring.

  • Print
  • Feedback

Archived Discussions (Read only)
Subject
. Forum migration complete By AthenAdministrator
. Forum migration update By AthenAdministrator
. Thanks By Anonymous
Resources