- Add jamon.jar to the application classpath
- Use JAMon's datasource proxy to monitor SQL
- Implement the JAMonServletFilter to monitor page hits
- Leverage Spring AOP via Spring's JamonPerformanceMonitorInterceptor class to monitor services
- Add a Spring filter to monitor Grails controllers.
JamonGrailsPlugin.groovy comes with a series of closures pre-defined. To change the datasource we add code to the doWithSpring closure. This closure allows you to update your Spring configuration.
We need to change the driverClassName to "com.jamonapi.proxy.JAMonDriver" and alter the url by adding "jamon:" after "jdbc:" and appending a parameter named "jamonrealdriver".
First lets add an import:
import javax.sql.DataSource
def doWithSpring = {
def config = application.config
def orgUrl = config.dataSource.url
def driverClassName = config.dataSource.driverClassName
String appendUrl = (orgUrl.contains('?')? '&': '?') + 'jamonrealdriver=' + driverClassName
if (orgUrl.contains("oracle:")) appendUrl = 'jamonrealdriver=' + driverClassName
def url = orgUrl.replace("jdbc:","jdbc:jamon:") + appendUrl
config.dataSource.url = url
config.dataSource.driverClassName = "com.jamonapi.proxy.JAMonDriver"
}
Step 3 is "implement the JAMonServletFilter to monitor page hits."
The doWithWebDescriptor closure will allow us to add our filter to the application. We need to append to both the <filter> and <filter-mapping> sections. Note that this is typical Grails builder code. The 'filter-mapping' node needs to be in quotes due to the hyphen in it's name:
def doWithWebDescriptor = { webXml ->
def filters = webXml.filter
filters + {
filter {
'filter-name'("jAMonServletFilter")
'filter-class'("com.jamonapi.http.JAMonServletFilter")
}
}
def filterMappings = webXml.'filter-mapping'
filterMappings + {
'filter-mapping' {
'filter-name'("jAMonServletFilter")
'url-pattern'("/*")
}
}
}
}