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管理、监控tomcat

OS:xp jdk:1.6 Tomcat:6.0.29 1.Java的环境变量配置正确,网上很多,不再说了 2.修改Tomcat目录下的bin\catalina.bat   在该文件中查找s...
  • yx511500623
  • yx511500623
  • 2014年10月14日 19:05
  • 3473

使用JMX监控Tomcat

1,什么是JMX        JMX是一种JAVA的正式规范,它主要目的是让程序有被管理的功能,那么怎么理解所谓的“被管理”呢?试想你开发了一个软件(如WEB网站),它是在24小时不间断运行的,那...
  • done58
  • done58
  • 2016年04月13日 15:45
  • 639

【JMX】2. JMX通知模型:Notification

复习 JMX构架中的各层及相关的组件 工具层(Instrumentation Level)     (a) MBeans(标准的,动态的,开放的和模型MBeans)     (b) 通知模型:No...
  • vking_wang
  • vking_wang
  • 2013年03月21日 14:16
  • 2066

jvirtualvm通过jmx远程连接jvm

jvirtualvm通过jmx远程连接jvm的配置和参数
  • wyh9459
  • wyh9459
  • 2017年03月19日 16:45
  • 376

为Web应用建立JMX管理系统(二)

四.创建MBean描述文件  在上面第三段代码中,我们可以看到,要将MBean注册到MBean Server中必须先创建MBeanInfo,MBean的setModelMBeanInfo()用来...
  • healxp
  • healxp
  • 2014年02月21日 10:58
  • 417

一、JMX官方指导文档 之 JMX概述

JMX概述 JMX(Java Management Exrensions)技术是标准Java平台的一部分。JMX技术从J2SE 5.0发布的时候添加到Java2平台。 JMX提供了一个标准的方法去管理...
  • jiaotuwoaini
  • jiaotuwoaini
  • 2017年05月01日 23:11
  • 365

如何使用JMX监控Kafka

使用kafka做消息队列中间件时,为了实时监控其性能时,免不了要使用jmx调取kafka broker的内部数据,不管是自己重新做一个kafka集群的监控系统,还是使用一些开源的产品,比如yahoo的...
  • u013256816
  • u013256816
  • 2016年12月08日 21:16
  • 7575

一句话介绍JMX——JMX基础

what?The Java Management Extensions (JMX) API is a standard API for management and monitoring of res...
  • lemon89
  • lemon89
  • 2015年05月09日 17:49
  • 1007

Java之——使用JMX监控Tomcat

2016年5月的最后一天,今天我将和大家分享Java中如何使用JMX来监控Tomcat的各种状态。好了,不多说了,我们直接进入主题 一、激活Tomcat的JMX远程配置 要通过JMX远程监控Tomca...
  • l1028386804
  • l1028386804
  • 2016年05月31日 17:25
  • 18800

linux操作系统,tomcat如何开启JMX

linux操作系统,tomcat如何开启JMX
  • liang_love_java
  • liang_love_java
  • 2016年01月16日 12:40
  • 3380
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:JMX access WEBLOGIC9.2
举报原因:
原因补充:

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