JMX access WEBLOGIC9.2

转载 2011年01月21日 12:59:00

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);

相关文章推荐

JMX access WEBLOGIC9.2

JMX access WEBLOGIC9.2 JMX access WEBLOGIC9.2 Development environment as well as the refe...

Java 版jmx 监控中间件weblogic

  • 2016-10-18 11:13
  • 46.98MB
  • 下载

在MyEclipse中部署Weblogic9.2中文版j2ee服务器

长久以来,我们都习惯了使用tomcat作为我们j2ee开发的服务器,虽然tomcat作为免费开源的服务器非常好用,但是它最多能支持到servlet而已,像分布式应用,集群等等高级领域统统不支持,毕竟它...

Spring 2.0.1 与 BEA WebLogic Server 9.2 的集成

http://www.oracle.com/technetwork/cn/topics/entarch/spring-2-weblogic-server-9-integrat-091510-zhs.h...

Linux 安装WebLogic9.2 MP2(图文详解 教程下载)

1      安装WebLogic9.2 MP2 1.1 准备安装介质 准备安装介质server922_zh_CN_linx32.bin (大概807M) 1.2 创建用户组和用户 创建用户组...

Weblogic9.2 建立域

1.    运行weblogic目录/home/bea/bea/weblogic92/common/bin/下的config.sh, 并按照提示建立名为web_domain的新域,主要步骤如下: ...

Weblogic9.2 cognos8.3 OpenDS 集成

好不容易整合出来了,本来写成了Word形式,呵呵  偷个懒 直接粘贴出来了,截图没有出来1    安装环境   i.      Windows 2003  ii....

weblogic的安装和配置--9.2

weblogic的安装和配置 1.weblogic部署前准备 把weblogic的bin包放到/opt/oracle目录下 1.1创建weblogic用户组 groupadd oinstall...

Integration WebLogic 9.2 with OAM 10.1.4.3(not using Proxy)

Environment: OAM and WebLogic 9.2 installed on same RHEL5.4 system.OAM Installed information:       ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)