The application of JMX in Tomcat

Source: Internet
Author: User
Tags snmp server memory
First, JMX simple introduction

Tomcat introduced JMX from version 5.0, trying to make JMX a future version of the management tool and platform for Tomcat. First, let's make a simple understanding of JMX. JMX is the acronym for Java Management Extension, which translates into Java Management tool extensions, meaning that JMX is not included in standard J2SE and we have to download the implementation of the JMX RI separately. However, this is a history of excluding JMX from J2SE, and j2se5.0 and j2se6.0 have already included the standard implementations of JMX. This shows that JMX has become an integral part of J2SE, and on the other hand, JMX has become the de facto standard of management tools on the Java platform, widely used in the industry. For example, JBOSS is based on JMX as a microkernel, WEB application modules and other functional modules can be hot plug into the micro-core, the JMX management function to play incisively and vividly. From the current industry usage, the X (Extension, extension) in JMX should be removed, and renamed to the Java Management Standard Platform (JMSP, Java Management Standard platform) is more appropriate. For backward compatibility, let's call it JMX.

What is the object that JMX manages, is the resource. What is a resource, a resource is a variety of applications and platforms in the enterprise, for example, a company may have many application servers, a number of WEB servers, a database server at most servers and file servers, and so on, if we want to monitor the database server memory usage, Or we want to change the number of JDBC maximum connection pools on the application server, but we don't want to restart the database and application server, which is typically resource management, that is, monitoring (monitoring, viewing) and managing our resources (Management, change), This monitoring and change does not prevent the current resource from running properly. Proper monitoring and management of resources allows our IT resources to run as smoothly as possible, providing our customers with a truly mean 24x7 service. We can monitor it through management tools and make thermal adjustments and jacks through management tools before the resource runs out or the hardware fails. Solitary nine swords, material enemy first, the appropriate resource management is our material enemy first tool, can let us stand in IT service of the invincible position. Before Sun came up with JMX (JSR174), people often used SNMP to manage resources on the network. The main problem with SNMP is that the entry threshold is too high and not easy to use. So Sun put forward the JSR174 initiative and provided a set of JMX reference implementations.

Technically, the JMX overall architecture can be divided into three layers, that is, the resource implantation layer (instrumentation level, there may be a better translation method.) , agent level, and Management layer (manager level), as described below:

Resource implantation layer (instrumentation level): This layer contains Mbeans and resources managed by these Mbeans, and Mbeans is a Java object that must implement the interfaces specified in the JMX specification. According to the JMX specification, in the interface of the Mbeans object, we can specify which properties the management has access to the resource, which methods of the resource can be invoked, and, in the event that the property of the resource changes, our Mbeans can send a message notifying other objects that are interested in the change of these attributes. The JMX specification defines four types of Mbeans, which are standard Mbeans (Standard mbeans), dynamic Mbeans (active Mbeans), open Mbeans (open Mbeans), and modal Mbeans (model MB EANs).

Agent layer (Agent level): The purpose of the agent layer is to expose the interfaces implemented in Mbeans to management, which is typically composed of Mbean server and Agent Services, which is a Mbeans object registrar, Some resource Mbeans are registered with this Mbean server, and object manager or other management-level applications can access the Mbean server to access the Mbeans registered in the Mbean server and, of course, monitor and manage these MBe Ans-bound resources.

Management level: Also known as the Distributed Service layer (distributed services), as the name suggests, this layer consists primarily of management applications that can access and manipulate the JMX Agent layer (agent level). These management applications can be either a WEB application or a Java SWT application.
Below, let's take a simple example to understand the concepts in JMX. Our family has a central heater system, which is a resource for our family and now we want to manage it through JMI. The existing code looks like this, and of course, for simplicity, we omit some JNI calling code, because the API provided by the manufacturer is written in C language.

A) Existing code for the Water heater interface (Centralheaterinf. Java):
Java code    package carl.test.jmx;      /**   * the  interface of central heater   *  @author  carlwu   *   * *     public interface centralheaterinf {      /**    * the heater is provided by british gas company   *     public final static string heater_provider =  "British Gas  company " ;      /**   * get current temperature  of heater   *  @return  the temperature of the heater    */    public int getcurrenttemperature ();          /**   * set the new temperature   *  @param   newtemperature &nbsp */    public void setcurrenttemperature ( int newtemperature);          /**   * turn on the heater   */     Public void turnon ();         /**   *  turn off the heater   */    Public void turnoff ();       }   
b) Existing code for the Water Heater Implementation code (CENTRALHEATERIMPL. Java)
Java code   /**   * the implemenation of central heater   *   @author  carlwu   *   */    package carl.test.jmx;        public class centralheaterimpl implements centralheaterinf {        int currenttemperature ;    public int  Getcurrenttemperature ()  {      return currentTemperature ;    }       public void setcurrenttemperature ( int newtemperature )  {      currentTemperature =newTemperature;   }        Public void turnoff ()  {      system. out  println (  "the heater is off. "  );   }        PublIc void turnon ()  {      system. out .println (  "the  heater is on.  " );   }      }   
1.1 Resource implantation Layer (instrumentation level) code example

How do we get JMX to manage our central water heaters? First of all, we do not want remote managers to be able to shut down our central water heaters, because once the water heater is closed, we will no longer be able to access the API provided by the manufacturer. Since it cannot be closed, we do not need to open the (Turnon) method in our Mbeans. So, we simply define the Mbeans interface as follows:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.