C H A P T E R  7

Daemon Monitor Statistics

This chapter describes the Daemon Monitor statistics that can be accessed from the NMA.

This chapter contains the following sections:


Example of Accessing Statistics Using an HTTP Client

The NmaMasterNametags example, the code of which is listed in Example 7–1, queries the PmdMasterStatisticsMBean for the list of daemon monitor nametags active on the master node. The mechanism used below (the invoke() method of the HTTPConnectorClient class) can be used to invoke the methods of the NMA MBeans and query the NMA for statistics and information.


EXAMPLE 7-1   NmaMasterNametags.java 
/*
* @(#)file      NmaMasterNametags.java
* @(#)author    Sun Microsystems, Inc.
* @(#)version   1.2
* @(#)date      02/06/06
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* This software is the proprietary information of Sun Microsystems, Inc.
* Use is subject to license terms.
*
* Copyright 2002 Sun Microsystems, Inc. Tous droits rservs.
* Ce logiciel est propriet de Sun Microsystems, Inc.
* Distribu par des licences qui en restreignent l'utilisation.
*/
 
// java import
//
import java.net.InetAddress;
 
// jmx import
//
import javax.management.ObjectName;
import javax.management.MBeanException;
 
// jdmk import
//
import com.sun.jdmk.TraceManager;
import com.sun.jdmk.comm.HttpConnectorClient;
import com.sun.jdmk.comm.HttpConnectorAddress;
import com.sun.jdmk.comm.CommunicationException;
import com.sun.jdmk.comm.UnauthorizedSecurityException;
 
 
/**
 * This java client uses an HTTP connector client to establish a connection
 * to the Master NMA and retrieve all Nametags.
 *
 * To compile the client:
 *
 * javac NmaMasterNametags.java
 *
 * Note: First ensure that the jar files specified in the chapter
 * 'Configuration Files, Dependencies and Requirements' of the
 * "Netra High Availability Suite 3.0
 * NMA Programming Guide" are in your CLASSPATH.
 *
 * To run the client:
 *
 * java NmaMasterNametags domain_name> master_IP_address>
 *  HttpConnectorServer_port>
 *
 * For example:  java NmaMasterNametags cluster_8 10.8.1.18 8081
 *
 * Notes:
 * 1) This example must be run on a machine with access to the
 * cluster, for example, the cluster install server.
 * 2) The second parameter can also be the master floating address, for
 * example, 10.8.1.1
 *
 */
 
public class NmaMasterNametags {
    
    public static void main(String argv[]) {
        
        try {
            
            /**
             * Debug
             * To activate the debug or trace mechanism from the command
             * line, use the syntax:
             * java -DLEVEL_DEBUG NmaMasterNametags arguments> or
             * java -DLEVEL_TRACE NmaMasterNametags arguments>
             *
             * For example:
             * java -DLEVEL_DEBUG NmaMasterNametags cluster_6 10.6.1.1 8081
             *
             */
            
            TraceManager.parseTraceProperties();
            
            // Set the domain name of the cluster
            //
            String domain = "DefaultDomain";
            if (argv.length >=1) domain = argv[0];
            
            // Set the host name of the remote MBean server.
            //
            String agentHost = InetAddress.getLocalHost().getHostName();
            if (argv.length >= 2) agentHost = argv[1];
            
            // Set the port number of the remote connector server.
            //
            int agentPort = 8081;
            if (argv.length >= 3)
                agentPort = Integer.decode(argv[2]).intValue();
            
            System.out.println(">>> Connecting to " + agentHost +
            " using port number " + agentPort);
            
            // Set up the HTTP Connector Client.
            //
            HttpConnectorClient connector = new HttpConnectorClient();
            
            try {
                // Initialize communication with the remote MBean server.
                //
                HttpConnectorAddress hca =
                new HttpConnectorAddress(agentHost,agentPort);
                connector.connect(hca);
            } catch (IllegalArgumentException e) {
                System.out.println("Connection exception! " +
                e.getMessage());
            } catch (CommunicationException e) {
                System.out.println("Connection exception! " +
                e.getMessage());
            } catch (UnauthorizedSecurityException e) {
                System.out.println("Connection exception! " +
                e.getMessage());
            }
            
            // Get Nametags
            //
            
            String[] iargs = {};
            String[] isig = {};
            
            String instanceName = domain + ".master:nhas-object=pmd_stats";
            ObjectName node =
            new ObjectName(instanceName);
            try {
                // Attempt to invoke getNameTags()
                //
                String[] nt = (String[])
                connector.invoke(node, "getNameTags", iargs, isig);
                
                System.out.println("Node " + argv[0] +
                " is running process groups:");
                // Print each element of the array returned by getNameTags()
                // to the standard output.  Each element is a nametag 
                // managed by the daemon monitor
                //
                for (int i = 0; i  nt.length; i++) {
                    System.out.println(nt[i]);
                }
            } catch (MBeanException e) {
                System.out.println("Got an exception invoking " +
                "getNameTags()! " + e.getTargetException().getMessage());
            }
            
            // Terminate communication with the remote MBean server.
            //
            connector.disconnect();
            
            // Exit program
            //
            System.exit(0);
            
        } catch (Exception e) {
            System.out.println("Got an exception !" + e.getMessage());
            e.printStackTrace();
            System.exit(1);
        }
    }
}


Introducing Daemon Monitor Statistics

The Daemon Monitor statistics are useful in maintaining awareness of processes that fail, and processes that are unable to restart within the allowed number of retries. Access to the process IDs (PIDs) of the processes allows for the monitoring of these processes using standard Solaris Operating System commands.



Note - Daemon Monitor statistics are cached. The com.sun.nhas.ma.pmd.cache.validity and com.sun.nhas.ma.pmd.polling properties in the nma.properties file control the Daemon Monitor polling interval and cache data validity period. If the values of these properties are set too low, the cache might be refreshed before all statistics cached in the previous polling period are read. The default values should be sufficient in most cases.



See Daemon Monitor in Netra High Availability Suite 3.0 1/08 Foundation Services Overview for more information about the Daemon Monitoring service.


Daemon Monitor Master Statistics

This section describes the Daemon Monitor statistics available from the NMA on the master node.

PmdMasterStatisticsMBean

The PmdMasterStatisticsMBean MBean provides the nametags of all daemons currently being monitored.

Getting All Nametags

To return all the nametags managed by the NMA, invoke the getNameTags method. The getNameTags method takes no parameters, and returns a String[].


Daemon Monitor Node Statistics

This section describes the Daemon Monitor statistics collected by the NMA on each peer node.

PmdStatisticsMBean

The PmdStatisticsMBean provides a list of all the nametags monitored by the Daemon Monitor.

Getting All Nametags

To return all the nametags managed by the Daemon Monitor, invoke the getNameTags method. The getNameTags method takes no parameters, and returns a String[].

PmdNameTagStatisticsMBean

The PmdNameTagStatisticsMBean MBean provides information about the number of attempts that can be made to restart a daemon, and the number of attempts that have already been made. This MBean is the source of:

One instance of this MBean is instantiated for each Daemon Monitor by the Daemon Monitor service.

Getting the Daemon Monitor Nametag

To get the nametag that the PmdNameTagStatisticsMBean MBean is providing data on, invoke the getNameTag method. The getNameTag method takes no parameters, and returns a String.

Getting the PIDs Associated With a Nametag

To get the list of process IDs associated with this nametag, invoke the getPidList method. The getPidList method takes no parameters, and returns an int[].

Getting the Daemon Monitor Maximum Retries

To get the maximum number of restart retries allowed for this nametag, invoke the getMaxRetryCount method. The getMaxRetryCount method takes no parameters, and returns an int.

Getting the Number of Retries for a Nametag

To number of restart retries already attempted for this nametag, invoke the getRetryCount method. The getRetryCount method takes no parameters, and returns an int.