Instrumenting Application Code

The application code needs to be instrumented to push data to the custom MBean. In order to minimize overhead check that JMX monitoring is turned on before pushing statistics to the MBean.

Figure 1. Pushing elapsed time statistics to the custom MBean
public void instrumentedMethod() {
 long startTime = System.currentTimeMillis();
 ...
 // do processing
 ...
 // check that JMX monitoring is enabled before
 // updating the MBean
 if(CuramJMXUtil.isJmxMonitoringEnabled()) {
  MyStats.updateStats("item",
       System.currentTimeMillis() - startTime);
 }
}

Another possible instrumentation is to add execution statistics to the existing JMX services such as transaction tracing and in-flight transaction data.

Figure 2. Pushing execution statistics to existing JMX services
public Result instrumentedMethod(String param) {
 try {
  return CuramJMXUtil.runAndRecord(new Callable<Result>(){
	public Result call() throws Exception {
		return myMethod(param);
	}}, "myMethod",
	TransactionInfo.getProgramUser());
 } catch (CuramJMXUtil.CallableException e) {
 	throw new AppRuntimeException(e.getCause());
 }
}