One option you have is to use AOP to hook into an existing application. I have done this successfully using Spring to monitor an applications log messages without it knowing a thing. This works if it using interfaces which you can 'hack' into using AOP. For instance, if your application uses a logger which is an interface, and it expects an implementation of this interface to work with, you can proxy the real logger implementation and get it to call your own implementation each time it logs something.
Hi,
It depends what you want to monitor in your application.
If you want to monitor JVM resource consumption, then you simply need to start the JVM JMX agent.
If you're running on JDK 6 with a Sun's JVM then you only need to start JConsole from
the same (user/machine), connect to your running process, and you will be able to
see all the data gathered by the JVM Monitoring & Management API. (local management)
If you're running on JDK 5, and/or if you want to monitor from a different (user/machine)
then start your app with the appropriate flags so that the JMX agent is enabled at start-up,
and then connect to it with JConsole.
see http://java.sun.com/developer/technicalArticles/J2SE/monitoring/
If you want to expose data which is specific to your application e.g. number of blah received, then you will need to write an MBean that will expose that data. You will also
need to register that MBean in the platform MBeanServer, and you will need to start your
application in one of the two ways exposed above.
Your application classes need not to be aware of the management layer, but you will
need to insert code at some point (e.g. in main()) that will register your new MBeans.
You could do this - for instance - by providing an alternate main:MyAppMainClass {
public static void main(String[] args) {...}
}
MyNewAppMainClass {
public static void main(String[] args) {
// register my new MBeans...
...
// start my app
MyAppMainClass.main(args);
}
}
You will find a lot of advices and information on developing management interfaces with JMX in the new JDK 6 JMX Sample - see
http://blogs.sun.com/jmxetc/entry/an_advanced_jmx_example_for
And for the basics, you may want to follow the new JDK 6 Tutorial Trail:
http://java.sun.com/docs/books/tutorial/jmx/
You will also find a bunch of links to JMX docs here:
http://blogs.sun.com/jmxetc/entry/the_new_jmx_tutorial_trail
Finally, <a href="http://weblogs.java.net/blog/emcmanus">Eamonn McManus</a>, JMX spec lead, did a talk at Java One 2006 where he evoked the different ways to link MBeans to application objects.
http://developers.sun.com/learning/javaoneonline/2006/coreplatform/TS-3523.html
Hope this will help you!
-- daniel
JMX, SNMP, Java, etc...
http://blogs.sun.com/jmxetc