Sun Microsystems
Products & Services
 
Support & Training
 
 

Previous Previous     Contents     Index     Next Next
Chapter 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 réservés.
* 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 Foundation Services 2.1 6/03
 * 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);
        }
    }
}

Previous Previous     Contents     Index     Next Next