I have added JMX support to the Simple Java Performance Counters. For a
detailed description on the Java Performance Counters please check out my
previous post located.
We expose JMX support by implementing a custom DynamicMBean known as JmxPerf.
Currently, we only expose the display value, but it might makes sense to expose
the raw value as well. This will allow JMX tools to sample the counter(s) and
chart progress. The JMX bean is exposed by calling the
PerfRegisty.registerJmxBeans(int jmxServerPort, int jmxRegistryPort) method.
Lets examine this method below located in PerfRegisty.java.
The JMX bean can only be registered once so calling the method multiple times
is safe and has no effect. Notice you can specific the jndi port to run the
registry at as well as the port of the actual bean, which are different.
Next, lets examine the methods that does the work in JmxPerf.java that
implements the dynamic bean interface. The getAttributes method uses the
PerfRegisty to enumerate the counters and return their results using
the display value method.
Conclusion
I hope this is was a helpful addition to the Simple Java Performance Counters.