[hibernate-dev] exposing statistics easier (HHH-3593 solution)

John Mazzitelli mazz at redhat.com
Wed Nov 19 09:49:02 EST 2008


I recently added support to Jopr, The JBoss management platform project 
( http://www.jboss.org/jopr ) to be able to monitor Hibernate via the 
Hibernate Statistics MBean.

For background, see my blog entry: 
http://management-platform.blogspot.com/2008/11/monitoring-hibernate.html

and more specifically, see the demo flash: 
https://docs.jbosson.redhat.com/confluence/display/JON2/Demo-MonitoringHibernate

If you watch that demo, you can see how useful the Hibernate Statistics 
data can be (e.g. when used by external management tools like Jopr you 
can track the performance of Hibernate over time, send alerts based on 
that performance data, etc. etc.).

But for users to be able to monitor their Hibernate applications from an 
external management tool, it isn't enough for them to specify the 
"hibernate.generate_statistics" configuration setting.  They must expose 
those statistics via JMX; however, that puts a burden on the Hibernate 
developer to write special code to do this (as the example code in the 
blog illustrates - see Max's comments on my blog and my responses also).

Out of that, I submitted this JIRA:

http://opensource.atlassian.com/projects/hibernate/browse/HHH-3593

Last night I wrote the code that implements this enhancement request and 
attached the patch to that JIRA. The short of it is, the Hibernate 
developer no longer has to write any Java code to expose the statistics 
via JMX, all you have to do is set these configuration settings:

hibernate.generate_statistics.jmx=true
hibernate.generate_statistics.jmx.object_name=hibernate:type=statistics,application=foo
hibernate.generate_statistics.jmx.mbeanserver=*platform*

If you set those, statistics generation will be turned on, the Hibernate 
Statistics MBean will be exposed via JMX and if you enabled the VM for 
remote JMX, you can immediately begin to monitor Hibernate (you'll even 
see the Hibernate MBean via jconsole, though things like Jopr will 
provide better functionality like viewing historical stat data, alerting 
and the like).

As the JIRA mentions, this patch does NOT introduce any JMX compile-time 
dependencies (due to the requirement that Hibernate be able to support 
JDK 1.4). Therefore, you will not see any "javax.management.*" imports 
or classes being used directly (they are used via reflection). However, 
if you enable this JMX statistics feature, obviously, you must run in 
JRE 5+ or JRE 1.4 + JMX libraries - if you do not, this code will log 
error messages saying what the problem is and simply disable the JMX 
stats capability (but otherwise, hibernate works normally).

Any suggestions how I might further this along to get it merged? Or is 
this patch good enough for some Hibernate developer to merge it in and 
take it over?

John Mazz



More information about the hibernate-dev mailing list