Showing posts with label JMX. Show all posts
Showing posts with label JMX. Show all posts

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!

Monday, September 13, 2010

Grails log4j JMX in one easy step

Here is a quick way to enable log4j control in JMX with Grails. Just update your resources.groovy like so:

import org.springframework.jmx.support.MBeanServerFactoryBean
import org.springframework.jmx.export.MBeanExporter
import org.apache.log4j.jmx.HierarchyDynamicMBean

beans = {
log4jBean(HierarchyDynamicMBean)

mbeanServer(MBeanServerFactoryBean) {
locateExistingServerIfPossible=true
}

exporter(MBeanExporter) {
server = mbeanServer
beans = ["log4j:hierarchy=default":log4jBean]
}
}

That's it. Now you can use jconsole to control your log4j settings, which during development/debug can be quite helpful. Of course you could take this much further by only enabling it in specific environments (e.g. development only), but that's up to you!