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.
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.
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()); } }