Disclaimer The opinions expressed herein are author's opinions and do not represent e-Zest's view in anyway. © Copyright 2010
Monitoring Java enabled resources either in distributed or non-distributed environments would have been thorny without JMX. What JMX technology does is that, it exposes these Java resources to be monitored using MBeans or Managed Beans. MBeans are JavaBeans really which represent the Java resources to be monitored and which can be accessed in the J2EE server. Exposing these resources as MBeans allows instrumentation. Consider a typical scenario, where Java developers troubleshoot database connection leaks, which is hard to troubleshoot. But imagine how much relaxing a Java developer would feel if the developer could see total number of connections being opened and closed while the application is running using some graphical tool. JMX technology provides set of tools and APIs, using which one can monitor the JVM resources.
jconsole
If you have installed J2SE 5.0, you already have a graphical tool knows as jconsole. This tool allows us to monitor local and remote JVMs. As discussed already, the technology responsible for all this is the JMX technology.
As said already, MBeans represent JVM resources. First of all, an MBean needs to be registered in the MBean Server. Also, all the MBeans need to have an object name of type javax.management.ObjectName. The JVM application which needs to be monitored provides the MBean Server to the JMX client. Now a tool, such as jconsole (JMX Client) simply connects to the MBean Server, to allow us to monitor the JVM resources.
Database Connection Pooling
Database connection pooling allows us to reuse connections. Bugs in connections are common, when some thread that demands the connection does not return it to the pool, by failing to close the connection after it does it's job. Obviously we need a monitoring tool, which can show the information related to connections, and we can then monitor how the pool is being utilized, and hence find the defective parts of the program. Hibernate session factory statistics
Hibernate 3 provides, lot of statistics related to the session factory. We need to enable the statistics for the session factory first. The MBeanServerFactory can allow us to access MBeanServer. After creating an instance of StatisticsService (the MBean you want) and giving it the MBeanName , you can register the MBean. Now once you have registered the MBean, you can call various methods on it and retrieve useful information which could range from number of sessions being opened or closed or total number of cached queries successfully or find the performance related to with your queries. All this information helps you to troubleshoot and optimize things in a great way.
How to monitor your web application running locally under Tomcat using jconsole
In Tomcat 5.0 and later versions, JMX support has been enhanced to a great extent. Apart for connection leakages, developers would want to monitor their application in terms of memory usage, garbage collection, total classes being loaded, and other vital information related to queries, which would allow developers to optimize their application. Below are simple steps how one would go about making the web application running under Tomcat to be monitored from jconsole in Windows environment.
1- To enable the local JMX agent, you can set CATALINA_OPTS for JMX (please see below Useful links) in the Tomcat startup script.
2- Start Tomcat and access your web application.
3- Run the jconsole utility and you will see that it has detected all Java applications running locally.
You can also use jconsole <pid> where pid is the process ID of the running JVM. For example see the Windows task manager for Tomcat process ID.
4- Now access different parts of your application to see how jconsole shows the information in various tabs.
5- To monitor the MBean registered in the MBeanServer click on the "MBean" tab of jconsole, and you can see how many sessions are being opened and closed as your application flows. You can also see statistics related to your queries. There is lot of statistics available there, and the scope for monitoring is enormous. Besides all these, you will surely want to see how your application utilizes memory by using the "Memory" tab in jconsole.
Useful links:
http://java.sun.com/j2se/1.5.0/docs/guide/management/jconsole.html http://www.hibernate.org/216.html http://irserver.ucd.ie/tomcat-docs/monitoring.html
Related posts
Comments
June 25. 2008 11:04
Pingback from fuzzlinks.comFuzzLinks.com » Monitoring database connection pooling
fuzzlinks.com
April 4. 2009 12:07
BONANZA BONANZA BONANZA ( BUY 2 OF OUR PRODUCT AND GET 1 OF THESAME PRODUCT FREE)If interested : d.dilard@hushmail.meSamsung i8510 INNOV8...$300SIDEKICK PHONES:Sidekick 3 ....$140Sidekick LX....$200Sidekick 2008...$250Apple Iphone 3G 16GB.....$450Apple Iphone 3G 8GB..$350Apple Iphone 4gb ...$200NOKIA PHONES:Nokia N95 8GB.....$200Nokia N96 16GB...$300Nokia N97...$400Nokia 8800 Arte Duo.........$250Nokia 5800..$200Motorola A3100...$200Motorola Aura...$550USDMotorola Q 11...$180Blackberry 8800 indigo unlocked..$220Blackberry 8700g.......180Blackberry 8100 Pearl Cingular unlocked..$160Blackberry Bold 9000..$250BlackBerry Pearl Flip 8220..$200Blackberry 8830 Verizon..$240Blackberry Storm 9500 cost $300Blackberry Storm 9530 cost $220CAMCODERCanon EOS - 20DA, 8,2 Megapixels Camara Digital SLR $ 700Canon EOS - 1DS Mark II, 17,2 Megapixel SLR Digital Camera $ 900Canon EOS-1D Mark II, 8,2 Megapixels intercambiables Lens SLRprofesional Digital Camera ---- $ 800Canon EOS - 5D (Body Only), 12,8 Megapixels SLR Digital Camera $ 800Canon EOS-1D Mark II N, 8,2 Megapixel, SLR, Digital Camera $ 600Canon EOS - 20D, 8,2 Megapixel SLR Digital Camera w /17 -85mmf/4-5.6 IS USMAutofocus Lens Kit, $ 700Nikon D2X, 12,4 Megapixels SLR Digital Camera$ 700Nikon D1X, (Refurbished) 5,47 Megapixel SLR Digital Camera $ 800Nikon D2Hs, 4,1 Megapixels, de alta velocidad, SLR Digital Camera $ 700Nikon D90 Digital Camera Body only : 800usdNikon D3 Digital Camera Body Only : 700usdNikon D3X, 12,4 Megapixels SLR Digital Camera$ 1200usdTHE ABOVE LISTED MOBILE PHONES ARE BRAND NEW PHONES WITH ALL THEIR COMPLETE ACCESSORIESAND CARRIES 1 FULL YEAR INTERNATIONAL WARRANTY.If interested: d.dilard@hushmail.me
Dominic Dillard