Tuesday, September 14, 2010

Grails JMX - Redux

Here is an updated resources.groovy with some additional JMX controls exposed. Thanks to schmolly159 on the #grails freenode IRC channel for the examples and suggestion!

beans = {
// JMX mBean server
mbeanServer(MBeanServerFactoryBean) {
locateExistingServerIfPossible=true
}

// log4j JMX
log4jBean(HierarchyDynamicMBean)

// Hibernate stats
hibernateStats(org.hibernate.jmx.StatisticsService) {
sessionFactory = ref("sessionFactory")
statisticsEnabled = true
}

// JMX exporter
exporter(MBeanExporter) {
server = mbeanServer
beans = [
"log4j:hierarchy=default": log4jBean,
"hibernate:name=HibernateStatistics": hibernateStats,
"dataSource:name=DataSource": ref("dataSource"),
"quartz:name=QuartzScheduler": ref("quartzScheduler")
]
}
}

A few things to note about the above configuration.

First, the "statisticsEnabled" property of the hibernate statistics bean must be after the sessionFactory otherwise the sessionFactory will reset this to the default of "false".

Second, the above also assumes you have the Quartz plug-in installed.

Otherwise, it's that simple.

Do you have any beans that you find yourself exposing through JMX? Let us know in the comments!

No comments:

Post a Comment