Table of Contents

Driven Administrator Guide

version 2.1.4

Using Java Management Extensions (JMX) with Driven

The Java Management Extensions (JMX) API is a standard API for managing and monitoring of resources, such as applications, devices, services, and the Java Virtual Machine (JVM). Typical uses of the JMX technology include:

  • Gathering statistics about application behavior

  • Notifying of state changes and erroneous conditions

Note
The JMX API includes remote access so that a remote management program can interact with a running application for these purposes.

Using a JMX Interface to a Driven Server

The scope CLI supports setting up a JMX interface for proxy scope queries to a Driven Server. This enables any tool supporting the JMX interface to monitor pre-canned statistics from Driven.

Prerequisite: Ensure that Driven is monitoring applications before completing the following steps.

Step 1: Start the scope CLI in daemon mode

In the driven-client directory, enter:

$ driven scope --jmx

Make sure that Scope JMX has started.

started Scope JMX

Step 2: Open a monitoring tool

For example, the JConsole monitoring tool helps you manage Driven operations.

With a web browser window open, start the command terminal and enter:

$ JConsole

The JConsole:New Connection window appears.

JMX_JConsole_Login

Figure 1: JConsole displays the "driven.management.scope.Scope --jmx" local process

Connect to driven.management.scope.Scope --jmx

Step 3: Navigate to Driven operations in the console

Click MBeans tab > driven.management.scope.Scope --jmx option > Operations option.

JMX_ExpandDrivenOperation

Figure 2: The Operations list of driven.management.scope.jmx

Step 4: View details about an operation

Highlight an option in the Operations list to view the MBeans operation information. Use the Operation invocation pane to launch specific details of the Driven operation.

API Details

The scope CLI supports several categories of methods with the JMX API.

Utility Methods

getProcessTypes();

getProcessTypes(); returns all process types in Driven. The types values are app, flow, step, and slice.

getTimeUnits();

getTimeUnits(); returns all time units. Values can be in DAYS, HOURS, or MINUTES.

getStatuses();

getStatuses(); returns all application statuses. Status can be SKIPPED, STARTED, SUBMITTED, RUNNING, SUCCESSFUL, STOPPED, or FAILED.

public List<String> getProcessTypes();
public List<String> getTimeUnits();
public List<String> getStatuses();

Operation Method

statusCounts( final String type );

statusCounts( final String type ); returns the number of your applications that are in FAILED, SUCCESSFUL, and STOPPED states.

public Map<String, Long> statusCounts( final String type );

Application-Specific Operations

findApps( String status, Integer amount, String timeUnit );

findApps ( String status, Integer amount, String timeUnit ); returns all applications with the values that you provided in your query. These attributes consist of the application’s status (SKIPPED, STARTED, SUBMITTED, RUNNING, SUCCESSFUL, STOPPED, or FAILED), time unit (DAYS, HOURS, or MINUTES), and the amount in the specified time unit.

findAppsWithDurationGreaterThan( String status, Integer duration, String timeUnit );

findAppsWithDurationGreaterThan( String status, Integer duration, String timeUnit ); returns the IDs for all applications in a particular status for more time than the duration, timeUnit parameters specify. For example, findAppsWithDurationGreaterThan ( RUNNING, 3, HOURS ) returns all IDs for applications that were in RUNNING state for more than 3 hours.

getAppDetail( String id );

getAppDetail( String id ) returns the application name and ID, start and finish times, its duration, and current status.

public List<String> findApps( String status, Integer amount, String timeUnit );
public List<String> findAppsWithDurationGreaterThan( String status, Integer duration, String timeUnit );
public Map getAppDetail( String id );

Attributes

The following attributes for JMX API integration can be automatically graphed in VisualVM.

public Long getTotalAppsRunning();
public Long getTotalFlowsRunning();
public Long getTotalStepsRunning();
public Long getTotalSlicesRunning();

Code Example of Method Call to Scope CLI Client

/**
 * An example of calling a method on Driven client scope JMX MBean
 */
public class JMXExample
  {
  public static void main( String[] args )
    {
    String host = "localhost";
// The port can be set in $DRIVEN_CLIENT_HOME/driven-env.sh
int port = 9010;
String url = "service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi";
try
  {
  JMXServiceURL serviceUrl = new JMXServiceURL( url );
  JMXConnector jmxConnector = JMXConnectorFactory.connect( serviceUrl, null );
  ObjectName objectName = new ObjectName( "driven.management.scope.jmx:type=DrivenScope" );
  try
    {
MBeanServerConnection conn = jmxConnector.getMBeanServerConnection();
/**
 * Example of getting a system attribute
 */
long count = (long) conn.getAttribute( objectName, "totalAppsRunning" );
System.out.format( "%d apps are currently in RUNNING state\n", count );
    /**
     * Example of invoking a method on the MBean
     */
    Map statuses = (Map) conn.invoke( objectName, "statusCounts", new Object[]{ "app" }, new String[]{ "java.lang.String" } );
    for ( Object item : statuses.keySet() )
      System.out.format("%s->%s\n", item, statuses.get(item) );
    }
  finally
    {
    if( jmxConnector != null )
      jmxConnector.close();
    }
  }
catch( Exception exception )
  {
  exception.printStackTrace();
  }
}
}