Monitoring agent activity

Use the AgentStatsMXBean API to monitor the activity of agents and events in the solution. The AgentStatsMXBean API retrieves information about the agents that are active in the solution, the number of events that are processed by the agents, and the time that elapsed during event processing.

About this task

You can use the methods in the AgentStatsMXBean API to monitor solution performance as agents receive and process events. The management interface is com.ibm.ia.runtime.management.AgentStatsMXBean.

Procedure

  1. Connect to the MBean server and create an MBeanServer instance for the application code that is running on the Liberty profile. See the Connecting to the MBean server topic for an example of the MBean server connection code.
  2. Activate the MBean interface by calling the javax.management.JMX.newMXBeanProxy method, which enables the MXBeans to obtain a proxy object. See Working with JMX MBeans on the Liberty profile in the Liberty documentation.
  3. Call the getAgentStats method and provide information about the solution or server to retrieve a list of performance statistics. The following example uses the AgentStatsMXBean API to retrieve information about the server partitions and then stores the retrieved statistics in a JSON object.
    try 
    {
       MBeanServerConnection mbsc = getMBeanServer(serverInfo, isCurrent);
       Set partitionNames = mbsc.queryNames(new ObjectName("com.ibm.ia:type=AgentStats,name=" + partition + ",*"), null);
       Iterator partitionIter = partitionNames.iterator();
       while (partitionIter.hasNext())
       {
          ObjectName partitionON = (ObjectName) partitionIter.next();
          
          Integer eventCount = (Integer) mbsc.getAttribute(partitionON, "EventCount");
          Integer agentCount = (Integer) mbsc.getAttribute(partitionON, "AgentCount");
          Long eventTime = (Long) mbsc.getAttribute(partitionON, "EventTime");
          Long agentTime = (Long) mbsc.getAttribute(partitionON, "AgentTime");
          
          JSONObject partitionJson = new JSONObject();
          partitionJson.put("id", partition);
          partitionJson.put("label", partition);
          partitionJson.put("eventCount", eventCount);
          partitionJson.put("agentCount", agentCount);
          partitionJson.put("eventTime", eventTime);
          partitionJson.put("agentTime", agentTime);
          
          partitionJson.put("eventTimeSeconds", TimeUnit.NANOSECONDS.toSeconds(eventTime));
          partitionJson.put("eventTimeMilliSeconds", TimeUnit.NANOSECONDS.toMillis(eventTime));
          partitionJson.put("agentTimeSeconds", TimeUnit.NANOSECONDS.toSeconds(agentTime));
          partitionJson.put("agentTimeMilliSeconds", TimeUnit.NANOSECONDS.toMillis(agentTime));
          
          array.add(partitionJson);
       }
    }
    catch (Exception exc)
    {
       exc.printStackTrace();
    }