This example shows the code for adding the totaltransactioncount statistic to the monitorable object tree. To add this statistic, objects are added to the monitorable object tree as follows:
The component that is represented by the class TransactionManagerImpl is added as a child of the server node of the tree. The name of the node is tx. The category is transactions. The dotted name of the monitorable object that represents the component is server.tx.
The totaltransactioncount statistic is added as a child of the tx node of the tree. The dotted name of the monitorable object that represents the statistic is server.tx.totaltransactioncount.
... import org.glassfish.flashlight.client.ProbeListener; import org.glassfish.flashlight.datatree.TreeNode; import org.glassfish.flashlight.datatree.factory.TreeNodeFactory; import org.glassfish.flashlight.statistics.Counter; ... public class TransactionManagerImpl { @Inject private MonitoringRuntimeDataRegistry mrdr; private TreeNode serverNode; private Counter totalTxCount = CounterFactory.createCount(); public void init (){ ... TreeNode txNode = TreeNodeFactory.createTreeNode("tx", null, "transactions"); TreeNode serverNode = getServerNode(); serverNode.addChild(txNode); ... totalTxCount.setName("totaltransactioncount"); txNode.addChild(totalTxCount); ... } ... private TreeNode getServerNode() { TreeNode serverNode = null; if (mrdr.get("server") != null) { serverNode = mrdr.get("server"); } else { serverNode = TreeNodeFactory.createTreeNode("server", null, "server"); mrdr.add("server", serverNode); } return serverNode; } ... }