How do we configure such that we obtain Hibernate statistics through JMX in Spring MVC based web applications. Is there any better way of tracking Hibernate performance.
Asked
Active
Viewed 8,196 times
2 Answers
8
Set hibernate.generate_statistics
to true
(either in persistence.xml
or in hibernate.cfg.xml
or in your session factory bean configuration). Then register this bean:
<bean id="hibernateStatisticsMBean" class="org.hibernate.jmx.StatisticsService">
<property name="statisticsEnabled" value="true" />
<property name="sessionFactory" value="#{entityManagerFactory.sessionFactory}" />
</bean>
(If you are not using JPA, just specify your sessionFactory
bean instead of getting it through the EMF)
And finally you need an mbean server and exporter:
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
<property name="locateExistingServerIfPossible" value="true" />
</bean>
<bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter"
lazy-init="false">
<property name="server" ref="mbeanServer" />
<property name="registrationBehaviorName" value="REGISTRATION_REPLACE_EXISTING"/>
<property name="beans">
<map>
<entry key="yourkey:name=hibernateStatistics" value-ref="hibernateStatisticsMBean" />
</map>
</property>
</bean>

Bozho
- 588,226
- 146
- 1,060
- 1,140
-
where would that be redirected. – Hareesh Ram Jul 15 '11 at 17:55
-
what do you mean redirected? You'll see it in JMX, but see my update, I forgot one bean – Bozho Jul 15 '11 at 19:57
-
Thanks Bozho. I did as advised. Could not see that reflected. Should I need to create a JMX agent explicitly or write an MBean exporter? – Hareesh Ram Jul 16 '11 at 15:00
0
Thanks Bozho for your inputs. I made two changes as specified below.
<bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false">
<property name="server" ref="mbeanServer" />
<property name="beans">
<map>
<entry key="Qvantel:name=hibernateStatistics"
value-ref="hibernateStatisticsMBean" />
</map>
</property>
<property name="registrationBehaviorName" value="REGISTRATION_REPLACE_EXISTING" />
</bean>

Nathan Feger
- 19,122
- 11
- 62
- 71

Hareesh Ram
- 335
- 1
- 4
- 15