Using Weblogic 5.1 - How can I extract runtime information about the server programatically ? I would like to gather the same information that the WebLogic console displays (e.g. connection pool information)

Xiang Rao

The following code segments can extract all the information Weblogic console displays. The APIs used are located at weblogic/classes/ directory. Weblogic does not publish the related Javadoc documents, but Java utility javap can at least extract the API signatures which will be enough for information gathering. It is said that Weblogic 6.0 will deprecate these APIs and will prefer standard JMX. If you want to traverse the whole tree in the left pane of Weblogic console, be warned as the total nodes created could be more than tens of thousands.

import java.util.*;
import javax.naming.*;

import weblogic.jndi.Environment;
import weblogic.common.*;
import weblogic.common.managedobject.*;
/**
  * WeblogicPerf is used to gather Weblogic Server 5.1 runtime performace information.
  * The clue of this program is from Dimitri's post on newsgroup weblogic.developer.interest.performance.
  * Please read the comments for customization. Weblogic Managed Object APIs can be found at 
  * weblogic/classes/weblogic/common/managedobject and Javadoc (signatures) can be generated by javap.
  * @Author: Xiang Rao
  * Email: xiangrao@hotmail.com
  * @Date: Oct. 20, 2000 
*/
public class WeblogicPerf{
    public static void main(String[] args){ 	
    	try{    
	    Environment env = new Environment();  // JNDI ENV
	    env.setProviderUrl("t3://localhost:7001");  // Weblogic URL
	    env.setSecurityCredentials(new T3User("system", "password"));
	    Context ctx = env.getInitialContext();  // JNDI CONTEXT
	    // servername is your weblogic.system.name
	    //JavaRemoteManageable manageable = (JavaRemoteManageable)ctx.lookup("weblogic.server.servername");
	    JavaRemoteManageable manageable = (JavaRemoteManageable)ctx.lookup("weblogic.server.myserver");
	    ManagedObjectDef mo = (ManagedObjectDef) manageable.getManagedObject();  //Get top level Managed Object
	    
	    // If you know the names of top level properties, get property values directly.
	    //   else you can use getManagedProperties() which returns an array
	    /*
	    InfoManagedProperty p;
	    p = (InfoManagedProperty)mo.getManagedProperty("MaximumHeapSpace");
	    System.out.println(p.getName() + " " + p.getValue());
	    p = (InfoManagedProperty)mo.getManagedProperty("QueueLength");
	    System.out.println(p.getName() + " " + p.getValue());
	    p = (InfoManagedProperty)mo.getManagedProperty("QueueThroughput");
	    System.out.println(p.getName() + " " + p.getValue());
	    */
	    
	    //Extract all top level properties, with Id and Value
	    //Note return value of getValue() is object, which could be array or ManagedObject
	    BaseManagedPropertyDef[] props =  mo.getManagedProperties();  
	    
	    if(props.length>0){
	    	System.out.println(props.length+" managed properties found.");
	        for(int i = 0; i<props.length;++i){
	            try{	
	                System.out.println("Managed Property "+i+": ID--"+props[i].getId()+" VALUE--"+props[i].getValue());
	                // An unexpected Null pointer will be thrown at the last item
	            }catch(Exception ex){
                ex.printStackTrace();	
	            }	
	        }	
	    	
	    }
	    //GetManagedSubObjects() will return all second level managed objects
	    //Names of second level objects are "EnvConfig", "ClientWorkspaces", "Connected", "Events"
	    //"JMS", "TimeServices", "Http", "Database", "Security", "NamingService", "DistributedObjects", "FileSystems",
	    //"ZACDirectories"
	    BaseManagedObjectDef[] bmod = mo.getManagedSubObjects();
	    
	    // If you know the key(name) of an object, you can use the key to extract the object as follows
	    //ManagedObjectDef zac = (ManagedObjectDef)mo.getManagedSubObject("ZACDirectories");
	    //System.out.println("Got ZAC "+zac);
	    //listProperties((ManagedObjectDef)zac,"");  //Also display properties of extracted sub managed object
	    //System.out.println("*************END ZAC***********"); 
	    
	    // Extract contents of the second level sub managed objects, keys, values, props, sub objects, etc
	    if(bmod.length>0){
	    	System.out.println(bmod.length+" managed object found.");
	        for(int i = 0; i<bmod.length;++i){
	            //if(i==9)continue;  //ignore Naming
	            /*try{
	                	
	                System.out.println("Managed Object "+i+": "+bmod[i].getClass().getName());
	                Class[] tmp = bmod[i].getClass().getInterfaces();
	                if(tmp.length>0){
	                    for(int j=0;j<tmp.length;j++)
	                        System.out.println("   --->"+tmp[j].getName());	
	                }
	            }catch(Exception ex){
	                ex.printStackTrace();	
	            }*/
	            //System.out.println("Managed Object "+i+": "+((ManagedObjectDef)bmod[i]).getClassDisplayName());
	            // getInstanceDisplayName() will expose the key of an managed object and related label in weblogic console
	            System.out.println("Managed Object "+i+": "+((ManagedObjectDef)bmod[i]).getInstanceDisplayName());
	            listProperties((ManagedObjectDef)bmod[i],"");  //Dispaly associated properties
	            // Use recursive to traverse the object tree in left pane of weblogic console. Not do not try to
	            // traverse subtree of Naming
	            // It is better to write some API to extract properties for specific node. If correct key(name)
	            // is not known, use this traverse method to search the name
	            if(i==6)loopLook((ManagedObjectDef)bmod[i],"");	
	        }	
	    	
	    }
	    
	    //loopLook(mo,"");
	}catch(Exception ex){
	    ex.printStackTrace();	
	}
	
	
    }	    
	    
    private static void loopLook(ManagedObjectDef mod, String pad){
    	try{
    	    String pad1 = pad;
    	    pad = pad+"    ";
    	    BaseManagedObjectDef[] bmod = mod.getManagedSubObjects();
    	    if(bmod == null)return;
	    if(bmod.length>0){
	    	System.out.println(pad+bmod.length+" managed object found.");
	        for(int i = 0; i<bmod.length;++i){
	            try{
	                	
	                //System.out.println(pad1+"Managed Object "+i+": "+((ManagedObjectDef)bmod[i]).getClassDisplayName());
	                System.out.println(pad1+"Managed Object "+i+": "+((ManagedObjectDef)bmod[i]).getInstanceDisplayName());
	                //Class[] tmp = bmod[i].getClass().getInterfaces();
	                //if(tmp.length>0){
	                    //for(int j=0;j<tmp.length;j++)
	                    //    System.out.println(pad+"   --->"+tmp[j].getName());	
	                //}
	                listProperties((ManagedObjectDef)bmod[i],pad);
	                if(((ManagedObjectDef)bmod[i]).getManagedSubObjects().length>0)loopLook((ManagedObjectDef)bmod[i],pad);
	                
	                //if(bmod[i].getManagedSubObjects()
	            }catch(Exception ex){
	                //ex.printStackTrace();	
	            }	
	        }	
	    	
 	    }
 	}catch(Exception ex){
 	    ex.printStackTrace();	
 	}
    }
    
    private static void listProperties(ManagedObjectDef mod, String pad){
    	try{
    	    BaseManagedPropertyDef[] props =  mod.getManagedProperties();
	    if(props==null)return;
	    if(props.length>0){
	    	System.out.println(pad+props.length+" managed properties found.");
	        for(int i = 0; i<props.length;++i){
	            try{	
	                if(props[i]!=null)System.out.println(pad+"Managed Property "+i+": ID--"+props[i].getId()+" VALUE--"+props[i].getValue());
	            }catch(Exception ex){
	                ex.printStackTrace();	
	            }	
	        }	
	    	
	    }
    	}catch(Exception ex){
    	    ex.printStackTrace();	
    	}
    }
	    
}
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact