Recently I was in need to tune some of the java services which I had implemented for for an iPhone project. When integrating services with mobile and hand held devices, it is very important that the services respond in a matter of seconds. In order to tune the services and get the best UI experience, the obvious step is to find the slowest service. However the intriguing question was ….HOW?
Following are some of the alternates most developers do
- Have a System.out / Log.debug after you enter and before you exit the service, which prints the time
- Write and aspect using AOP and log the time before and after invocation of the method
Serious developers choose the second approach, since monitoring is a cross cutting concern.
Before you fire up you IDE and start writing an Aspect and all those AOP jargon, I would like to introduce you to a class from the Spring Framework core portfolio called “JamonPerformanceMonitorInterceptor”. As the name suggests, it is an AOP interceptor that hooks into the framework called JAMon. JAMon is a java monitoring framework and it sure is sweet.
To know more about JAMon check it out HERE. Make sure you download the jamon-2.7.jar file and put it on your classpath
That’s right, no writing of interceptors and joint points and what not AOP jargon out there.
All you need to to do is instantiate a JamonPerformanceMonitorInterceptor bean and tell it which all Spring beans to intercept
Add this to instantiate the bean
<bean id="jamonPerformanceMonitorInterceptor" class="org.springframework.aop.interceptor.JamonPerformanceMonitorInterceptor" > <property name="trackAllInvocations" value="true"></property> <property name="useDynamicLogger" value="true"></property> </bean>
Next create a “BeanNameAutoProxyCreator” and hook in the interceptor.
<bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="interceptorNames"> <list> <idref bean="jamonPerformanceMonitorInterceptor"/> </list> </property> <property name="beanNames"> <list> <value>aRegularSpringBean</value> <value>statisticsDao</value> <value>statisticsService</value> <value>paymentDao</value> <value>paymentService</value> </list> </property> </bean>
All you need to do now is, tell the BeanNameAutoProxyCreator which all Spring beans to intercept.”paymentDao”,”paymentService” etc are all classic Spring beans. Voila, your services and dao are all being monitored.
Oh…And one last thing.
Make sure you set the log4 logging level to TRACE or else it will NOT work!!
In the follow article , I shall show you have to generate reports from the JAMON framework using a simple servlet.
You can actually avoid setting log4j trace level and still track all invocations. In your interceptor definition set “trackAllInvocations” to true:
Here is the reference : http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/aop/interceptor/JamonPerformanceMonitorInterceptor.html#setTrackAllInvocations(boolean)
Thanks for the information. Didnt know that. Hope to try it out sometime.
Regards,
Franklin
“In the follow article , I shall show you have to generate reports from the JAMON framework using a simple servlet.”
When will this be available.
Thanks
“In the follow article , I shall show you have to generate reports from the JAMON framework using a simple servlet.”
When will this be available.
Thanks
Answer this question please.
For over 4 years we are developing Java Simon as “Jamon clone” with nanosecond based measuring and a bit of more features thrown in – but still keeping it very simple for use. We also offer Spring interceptor and ServletFilter + little neat web console to watch your application. Check it here: http://code.google.com/p/javasimon/
Actually, this is directly the wiki page with instructions and examples: http://code.google.com/p/javasimon/wiki/JavaEE
Looks pretty cool. I sure will give this a try.
Regards,
Franklin
[…] https://javasight.wordpress.com/2010/10/04/monitoring-with-spring-and-jamon-using-jamonperformancemon… […]
kindly can u provide a complitlly example spring with jmon