关闭

JMX access WEBLOGIC9.2

标签: weblogicjmxaccessattributesstringparameters
2128人阅读 评论(0) 收藏 举报
分类:

JMX access WEBLOGIC9.2

Development environment as well as the reference packet
weblogic9.0 running on JDK5.0 or higher than the 5.0 version.
JAR package reference:
Only need to introduce weblogic .jar can be had, weblogic9.2's JAR size is about 51.4 MB.
Do not need the introduction of JMX packages , such as mx4j.jar

Open Pre-development process:
A good programming practice is conducive to this end, we will be some commonly used parameters extracted, placed in a separate class, are as follows:

/**
* @author leonelwong@126.com
* @version 0.9 2010-3-24 9:48:59 Information stored constants
*/
public class Constant {

public static String ServerProtocol = "t3";

public static String ServerIp = "127.0.0.1";

public static String ServerJndiroot = "/jndi/";

public static int ServerPort = 7001;

public static String ServerUsername = "weblogic";

public static String ServerPassword = "weblogic";

public static String ServerClassName = "weblogic.management .mbeanservers.domainruntime";

public static String ServerPROTOCOLName ="weblogic.management.remote";

public static String ThreadPoolRuntime = "ThreadPoolRuntime";

public static String JDBCConnectionPoolRuntime = "JDBCConnectionPoolRuntime";

public static String WebAppComponentRuntime = "WebAppComponentRuntime";

/**
* Thread all property
*/
public static String[] THREAD_ATTRIBUTES = { "CompletedRequestCount",
"ExecuteThreadIdleCount", "ExecuteThreadTotalCount", "HealthState",
"HoggingThreadCount", "MinThreadsConstraintsCompleted",
"MinThreadsConstraintsPending", "Name", "Parent",
"PendingUserRequestCount", "QueueLength",
"SharedCapacityForWorkManagers", "StandbyThreadCount", "Suspended ",
"Throughput", "Type" };

/**
* JDBC All property
*/
public static String[] JDBC_ATTRIBUTES = { "ActiveConnectionsAverageCount",
"ActiveConnectionsCurrentCount", "ActiveConnectionsHighCount",
"ConnectionDelayTime", "ConnectionLeakProfileCount",
"ConnectionsTotalCount", "CurrCapacity", "DeploymentState",
"Enabled", "FailuresToReconnectCount", "HighestNumAvailable",
"HighestNumUnavailable", "LeakedConnectionCount", "MaxCapacity",
"ModuleId", "Name", "NumAvailable", "NumUnavailable", "Parent",
"PoolState", "Properties", "State", "StatementProfileCount",
"Type", "VersionJDBCDriver", "WaitingForConnectionCurrentCount",
"WaitingForConnectionHighCount", "WaitSecondsHighCount" };

/**
* webapp All property
*/
public static String[] WEBAPP_ATTRIBUTES = { "ComponentName",
"ContextRoot", "DeploymentState",
"FilterDispatchedRequestsEnabled", "IndexDirectoryEnabled",
"JSPCompileCommand", "JSPDebug", "JSPKeepGenerated",
"JSPPageCheckSecs", "JSPVerbose", "LogFilename", "ModuleId",
"ModuleURI", "Name", "OpenSessionsCurrentCount",
"OpenSessionsHighCount", "Parent", "ServletReloadCheckSecs",
"ServletSessionsMonitoringIds", "SessionCookieComment",
"SessionCookieDomain", "SessionCookieMaxAgeSecs",
"SessionCookieName", "SessionCookiePath", "SessionIDLength",
"SessionInvalidationIntervalSecs", "SessionMonitoringEnabled",
"SessionsOpenedTotalCount", "SessionTimeoutSecs",
"SingleThreadedServletPoolSize", "SourceInfo", "Status", "Type" };

public static String ExecuteThreads = "ExecuteThreads";
}


Maybe you have discovered, and 9.2 parameters have been many more than the 7.0, so many parameters does it mean that 9.2 of the access method as opposed to 7.0 of the access methods and sampling method is different from that seen it.
9.2 The access methods are mainly based MbeanServerConnection this class there were also some MbeanHome of methods, such as queryMBeans (parameter 1, parameter 2), as MbeanHome, 9.2 inside, has been marked as obsolete.
Here we will JMX way to access weblogic9.2.

import

 java.io.IOException;
import java.util.ArrayList;
import java.util.Hashtable ;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.management.Attribute;
import javax.management.AttributeList;
import javax.management.MBeanServerConnection;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.naming.Context;
import weblogic.management.runtime.ExecuteThread;

/**
* @author leonelwong@126.com
* @version 0.9 2010-3-24 15:26:03 JMX Access webLogic9.2
*/
public class WebLogicJMXConsole {
JMXConnector connector = null;

MBeanServerConnection mscon = null;

private List threadPools;

private List JDBCPools;

private List wabAppPools;

/**
* Get the JMX API client connector . Use this type of object you can establish a connection to a connector server <br>
* Through the environment defined default parameters for this object <br>
* Objects created by the JMXConnectorFactory.connect connected <br>
* Pass the returned object can be MBeanServerConnection
*/
protected void initParams() {
// This object needs to be close
try {
threadPools = new ArrayList();
JDBCPools = new ArrayList();
wabAppPools = new ArrayList();
// JMX API The connector server address objects
JMXServiceURL serviceURL = new JMXServiceURL(Constant.ServerProtocol,Constant.ServerIp,Constant.ServerPort, Constant.ServerJndiroot + Constant.ServerClassName);
Hashtable h = new Hashtable();
h.put(Context.SECURITY_PRINCIPAL, Constant.ServerUsername);
h.put(Context.SECURITY_CREDENTIALS, Constant.ServerPassword);
h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,Constant.ServerPROTOCOLName);
connector = JMXConnectorFactory.connect(serviceURL, h);
mscon = connector.getMBeanServerConnection();
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* Print out the thread information
*/
public void printThreadMbeansInfo() {
try {
if (threadPools.size() < 1) {
return;
}
System.out.println("============================ Output thread information =====================================");
for (int p = 0; p < threadPools.size(); p++) {
System.out.println((ObjectName) threadPools.get(p));
Set mbeans = mscon.queryMBeans((ObjectName) threadPools.get(p),null);
System.out.println(" A total of :" + mbeans.size() + " Matches ");
for (Iterator itr = mbeans.iterator(); itr.hasNext();) {
ObjectInstance objectIns = (ObjectInstance) itr.next();
AttributeList aList = mscon.getAttributes(objectIns.getObjectName(), Constant.THREAD_ATTRIBUTES);
for (int i = 0; i < aList.size(); i++) {
Attribute att = (Attribute) aList.get(i);
System.out.println(att.getName() + " :"+ att.getValue());
}
ExecuteThread[] executeThreads = (ExecuteThread[]) mscon.getAttribute(objectIns.getObjectName(),Constant.ExecuteThreads);
if (executeThreads != null) {
System.out.println("============================ More thread information =====================================");
for (int j = 0; j < executeThreads.length; j++) {
System.out.println("Name :"+ executeThreads[j].getName());
System.out.println("Total Requests :" + executeThreads[j].getServicedRequestTotalCount());
System.out.println("Current Request :"+ executeThreads[j].getCurrentRequest());
System.out.println("Transaction :"+ executeThreads[j].getTransaction());
System.out.println("User :"+ executeThreads[j].getUser());
System.out.println("Idle :"+ executeThreads[j].isIdle());
//System.out.println("Stuck :"+ executeThreads[j].isStuck());
//System.out.println("Hogger :"+ executeThreads[j].isHogger());
//System.out.println("Standby :"+ executeThreads[j].isStandby());
System.out.println("=========================================================================");
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* Print out a JDBC connection pool related data
*/
public void printJDBCMbeansInfo() {
System.out.println("============================ Output JDBC information =====================================");
printMbeansInfo(JDBCPools, Constant.JDBC_ATTRIBUTES);
}
/**
* Print out the WEBAPP related data
*/
public void printWebAppMbeansInfo() {
System.out.println("============================ Output WEBAPP information =====================================");
printMbeansInfo(wabAppPools, Constant.WEBAPP_ATTRIBUTES);
}

/**
* Print out the specified information related data
*/
public void printMbeansInfo(List utilList,String[] arrays) {
try {
if (utilList.size() < 1) {
return;
}
System.out.println(" A total of :" + utilList.size() + " Matches ");
for (int p = 0; p < utilList.size(); p++) {
System.out.println((ObjectName) utilList.get(p));
Set mbeans = mscon.queryMBeans((ObjectName) utilList.get(p),null);
for (Iterator itr = mbeans.iterator(); itr.hasNext();) {
ObjectInstance objectIns = (ObjectInstance) itr.next();
AttributeList aList = mscon.getAttributes(objectIns.getObjectName(), arrays);
for (int i = 0; i < aList.size(); i++) {
Attribute att = (Attribute) aList.get(i);
System.out.println(att.getName() + " :"+ att.getValue());
}
System.out.println("===========================================================================");
}
}
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* Read the information, and the appropriate data into corresponding List In
*/
public void fortch4SetList() {
try {
Set mbeans = mscon.queryNames(null, null);
if(mbeans==null){
return;
}
//System.out.println(" Length :" + mbeans.size());
for (Iterator itr = mbeans.iterator(); itr.hasNext();) {
ObjectName objectName = (ObjectName) itr.next();
// Get all the threads. ObjectName
if (objectName.getCanonicalName().indexOf("Type=" + Constant.ThreadPoolRuntime) > -1) {
threadPools.add(objectName);
}
// Get all JDBC ObjectName
if (objectName.getCanonicalName().indexOf("Type=" + Constant.JDBCConnectionPoolRuntime) > -1) {
JDBCPools.add(objectName);
}
// Get all the webApp ObjectName
if (objectName.getCanonicalName().indexOf("Type=" + Constant.WebAppComponentRuntime) > -1) {
wabAppPools.add(objectName);
}
//System.out.println(objectName.getCanonicalName());
}
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* Close the connection
*/
public void closeConnection() {
try {
if (this.connector != null) {
this.connector.close();
}
} catch (IOException e) {
e.printStackTrace();
}

}

public static void main(String[] args) {
WebLogicJMXConsole test = new WebLogicJMXConsole();
test.initParams();
test.printThreadMbeansInfo();
test.fortch4SetList();
test.printJDBCMbeansInfo();
test.printWebAppMbeansInfo();
test.closeConnection();
}
}



The same is by visiting queryMBeans method, we can also get Set encapsulated data, but these Set the type of data encapsulation and 7.0 but not the same, who are interested can track what the data type of all ObjectInstance, so we value also can not use the previous approach to value, and needs the Attribute class to value, is obtained from the ObjectInstance, you can get through the following ways
ExecuteThread [] executeThreads = (ExecuteThread []) mscon.getAttribute (objectIns.getObjectName (), Constant.ExecuteThreads)
You can also enter a series of attributes to return to the AttributeList, and then an iterative way, one by one to obtain the name and the value of each Attribute
AttributeList aList = mscon.getAttributes (objectIns.getObjectName (), Constant.THREAD_ATTRIBUTES);

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:452841次
    • 积分:5084
    • 等级:
    • 排名:第5456名
    • 原创:32篇
    • 转载:230篇
    • 译文:0篇
    • 评论:46条
    最新评论