DateFormat df = new SimpleDateFormat("yyyy.MM.dd 'at' HH:mm:ss z"); ObjectName statsManagement = new ObjectName(StatsManagementMBean.OBJECT_NAME); StatsManagementMBean mbean = (StatsManagementMBean) getMBeanProxy(statsManagement, StatsManagementMBean.class, false); long sessionId = mbean.createSession(); int nodeId = 0; // "all nodes" int activeRootSbbs = mbean.subscribeCounter(sessionId, nodeId, "Services", "activeRootSbbs", SubscriptionMode.SIMPLE_GAUGE); int activeActivities = mbean.subscribeCounter(sessionId, nodeId, "Activities", "active", SubscriptionMode.SIMPLE_GAUGE); // rhino will begin gathering samples every 1 sec mbean.startCollecting(sessionId, 1000); while (true) { Thread.sleep(5000); Snapshot[] snapshots = mbean.getAccumulatedSamples(sessionId); for (int i = 0; i < snapshots.length; i++) { Snapshot snapshot = snapshots[i]; String date = df.format(new Date(snapshot.getTimestamp())); int[] subsIds = snapshot.getSubscriptionIds(); for (int j = 0; j < subsIds.length; j++) { final int subsId = subsIds[j]; if (subsId == activeActivities) System.out.println(date + ": active activities="+snapshot.getData()[j][0]); else if (subsId == activeRootSbbs) System.out.println(date + ": active SBBs="+snapshot.getData()[j][0]); else System.err.println("Unknown subscription id: "+subsId); } } }