通過JMX監控weblogic服務
阿新 • • 發佈:2019-02-14
一、JMX簡介
JMX是一種JAVA的正式規範,它主要目的是讓程式有被管理的功能,那麼怎麼理解所謂的“被管理”呢?試想你開發了一個軟體(如WEB網站),它是在24小時不間斷執行的,那麼你可能會想要“監控”這個軟體的執行情況,比如收到了多少資料,有多少人登入等等。或者你又想“配置”這個軟體,比如現在訪問人數比較多,你想把資料連線池設定得大一些。
當然,你也許會專門為這些管理來開發軟體,但如果你藉助JMX,則會發現建立這樣的管理程式是如此簡單。因為你無需為管理程式來開發介面,已經有通用的JMX管理軟體,如MC4J,或者是用一般都附帶提供的HTML網頁來管理,你要做的僅僅是將自己要被管理和監控類的按照JMX規範修改一下即可。
中介軟體軟體WebLogic的管理頁面就是基於JMX開發的,而JBoss則整個系統都基於JMX構架。
二、監控Weblogic
下面介紹下如何通過jmx獲取監控資訊。
1、服務基本資訊資訊
/** * 建構函式 */ public WebLogicMiddlewareAdapter(JMXSession jmxSession) { currentTime = CommonUtils.getCurrentTime(); this.jmxSession = jmxSession; serverRuntime = (ObjectName) jmxSession.getAttribute(runtimeService, "ServerRuntime"); applicationRuntimes = (ObjectName[]) jmxSession.getAttribute(serverRuntime, "ApplicationRuntimes"); } /** * @see com.comtop.numen.monitor.collection.appservice.middleware.adapter.MiddlewareAdapter#getMiddleWareBaseInfomation() */ @Override public MiddleWareBaseInfoVO getMiddleWareBaseInfomation() { MiddleWareBaseInfoVO objWebLogic = new MiddleWareBaseInfoVO(); try { objWebLogic.setMiddlewareId(CommonUtils.getUUID()); objWebLogic.setWebContext(this.getWebConext()); if (JMXConstonts.JMX_COLLECT_EXTENDS.equals(jmxSession.getNodeInfoVO().getIsJmxExtends())) { // 獲取程序ID objWebLogic.setMiddleWarePid(getMiddlewarePID()); } // 服務名稱 objWebLogic.setServerName(jmxSession.getStringAttribute(runtimeService, "ServerName")); // Domain名稱 ObjectName objConfig = (ObjectName) jmxSession.getAttribute(runtimeService, "DomainConfiguration"); objWebLogic.setDomainName(jmxSession.getStringAttribute(objConfig, "Name")); String strWLVersion=jmxSession.getStringAttribute(serverRuntime, "WeblogicVersion"); strWLVersion=strWLVersion.substring(strWLVersion.lastIndexOf("WebLogic"), strWLVersion.length()-1); objWebLogic.setRunnningState(jmxSession.getStringAttribute(serverRuntime, "State")); objWebLogic.setListenAddress(jmxSession.getStringAttribute(serverRuntime, "ListenAddress")); objWebLogic.setListenPort(jmxSession.getStringAttribute(serverRuntime, "ListenPort")); objWebLogic.setAdminServerHost(jmxSession.getStringAttribute(serverRuntime, "AdminServerHost")); objWebLogic.setAdminServerListenPort(jmxSession.getStringAttribute(serverRuntime, "AdminServerListenPort")); objWebLogic.setAdministrationPort(jmxSession.getStringAttribute(serverRuntime, "AdministrationPort")); objWebLogic .setOpenSocketsCurrentCount(jmxSession.getIntAttribute(serverRuntime, "OpenSocketsCurrentCount")); objWebLogic .setSocketsOpenedTotalCount(jmxSession.getIntAttribute(serverRuntime, "SocketsOpenedTotalCount")); objWebLogic.setRestartsTotalCount(jmxSession.getIntAttribute(serverRuntime, "RestartsTotalCount")); objWebLogic.setSSLListenAddress(jmxSession.getStringAttribute(serverRuntime, "SSLListenAddress")); long lTime = (Long) jmxSession.getAttribute(serverRuntime, "ActivationTime"); } catch (Exception e) { LOGGER.error("採集WebLogic資訊出錯" + e.getMessage()); return null; } return objWebLogic; }
2、JDBC資訊
public JDBCInformationVO getJDBCInfomation() { JDBCInformationVO objJDBC = new JDBCInformationVO(); try { List<JDBCDetailVO> lstJdbcDetail = new ArrayList<JDBCDetailVO>(); List<JDBCInformationVO> lstJdbc = new ArrayList<JDBCInformationVO>(); String strJdbcId = CommonUtils.getUUID(); // 獲取域配置物件 ObjectName domainConfig = (ObjectName) jmxSession.getAttribute(runtimeService, "DomainConfiguration"); ObjectName[] objJDBCSystemResources = (ObjectName[]) jmxSession.getAttribute(domainConfig, "JDBCSystemResources"); ObjectName jdbcSRName = (ObjectName) jmxSession.getAttribute(serverRuntime, "JDBCServiceRuntime"); ObjectName[] objJDBCDataSource = (ObjectName[]) jmxSession.getAttribute(jdbcSRName, "JDBCDataSourceRuntimeMBeans"); // 定義jdbcUtils物件 JDBCDetailVO objJDBCdetail = null; ObjectName objJdbcResource = null; ObjectName objPoolPrms = null; for (int i = 0; i < objJDBCDataSource.length; i++) { objJDBCdetail = new JDBCDetailVO(); objJDBCdetail.setDetailId(CommonUtils.getUUID()); objJDBCdetail.setJdbcId(strJdbcId); // 判斷JDBCSystemResources物件是否為null if (objJDBCSystemResources[i] != null) { objJdbcResource = (ObjectName) jmxSession.getAttribute(objJDBCSystemResources[i], "JDBCResource"); objPoolPrms = (ObjectName) jmxSession.getAttribute(objJdbcResource, "JDBCConnectionPoolParams"); // 總的連線數 objJDBCdetail.setMaxCapacity(jmxSession.getIntAttribute(objPoolPrms, "MaxCapacity")); objJDBCdetail.setIncreseCapacity(jmxSession.getIntAttribute(objPoolPrms, "CapacityIncrement")); objJDBCdetail.setInitCapacity(jmxSession.getIntAttribute(objPoolPrms, "InitialCapacity")); // 資料來源名稱 String objDataSourceName = this.getJndiName(objJdbcResource); if (objDataSourceName == null) { break; } objJDBCdetail.setDataSourceName(objDataSourceName); } // 最大歷史的連線數 objJDBCdetail.setHisMaxConn(jmxSession.getIntAttribute(objJDBCDataSource[i], "ActiveConnectionsHighCount")); // 驅動版本 objJDBCdetail.setDriverName(jmxSession.getStringAttribute(objJDBCDataSource[i], "VersionJDBCDriver")); // 資料來源狀態 objJDBCdetail.setDataSourceState(jmxSession.getStringAttribute(objJDBCDataSource[i], "State")); // 當前容量 objJDBCdetail.setCurrCapacity(jmxSession.getIntAttribute(objJDBCDataSource[i], "CurrCapacity")); // 當前活動的連線數 objJDBCdetail.setCurrConnection(jmxSession.getIntAttribute(objJDBCDataSource[i], "ActiveConnectionsCurrentCount")); // 資料來源洩漏的連線數 objJDBCdetail.setLeakConn(jmxSession.getIntAttribute(objJDBCDataSource[i], "LeakedConnectionCount")); // 當前等待連線數 objJDBCdetail.setCurrWaitConn(jmxSession.getIntAttribute(objJDBCDataSource[i], "WaitingForConnectionCurrentCount")); // 歷史等待連線數 objJDBCdetail.setHisMaxWaitConn(jmxSession.getIntAttribute(objJDBCDataSource[i], "WaitingForConnectionTotal")); // 當前可用連線數 objJDBCdetail.setCurrVailableConn(jmxSession.getIntAttribute(objJDBCDataSource[i], "NumAvailable")); // 失敗重連數 objJDBCdetail.setFailReConn(jmxSession .getIntAttribute(objJDBCDataSource[i], "FailuresToReconnectCount")); } objJDBC.setDetail(lstJdbcDetail); objJDBC.setJdbcInfo(lstJdbc); } catch (Exception e) { LOGGER.error("採集JDBC資訊出錯" + e.getMessage()); return null; } return objJDBC; }
3、JVM記憶體資訊以及GC資訊
public JVMInformationVO getJVMInfomation() {
JVMInformationVO objJVM = new JVMInformationVO();
try {
objJVM.setJvmId(CommonUtils.getUUID());
ObjectName objName = (ObjectName) jmxSession.getAttribute(serverRuntime, "JVMRuntime");
// jvm 記憶體使用情況
double memoryMaxSize =
Double.parseDouble(String.valueOf(jmxSession.getAttribute(objName, "HeapSizeCurrent")));
double memoryFreeSize =
Double.parseDouble(String.valueOf(jmxSession.getAttribute(objName, "HeapFreeCurrent")));
// double memoryPer = (memoryMaxSize - memoryFreeSize) / memoryMaxSize * 100;
objJVM.setJvmHeapTotalSize(String.valueOf(CommonUtils.getDoubleToPattern(memoryMaxSize, 2)));
objJVM.setJvmHeapUsedSize(String.valueOf(CommonUtils
.getDoubleToPattern((memoryMaxSize - memoryFreeSize), 2)));
objJVM.setCreateDate(currentTime);
objJVM.setNodeId(jmxSession.getNodeInfoVO().getNodeInfoId());
objName = (ObjectName) jmxSession.getAttribute(serverRuntime, "JVMRuntime");
objJVM.setJavaVersion(jmxSession.getStringAttribute(objName, "JavaVersion"));
objJVM.setRunningState(jmxSession.getStringAttribute(serverRuntime, "State"));
objJVM.setNodeInfoVO(jmxSession.getNodeInfoVO());
/**************************************
* 採集擴充套件資訊
************************************/
if (JMXConstonts.JMX_COLLECT_EXTENDS.equals(jmxSession.getNodeInfoVO().getIsJmxExtends())) {
this.getJVMExtendsInfo(objJVM);
}
} catch (Exception e) {
LOGGER.error("採集JVM記憶體資訊時出錯" + e.getMessage());
return null;
}
return objJVM;
}
/**
* 獲取GC資訊
*
* @param strName
* @param session
* @param objVO
* @return
*/
public Map<String, String[]> getGCInfo(String[] strName, JMXSession session, JVMInformationVO objVO) {
Map<String, String[]> objGCMap = new HashMap<String, String[]>(5);
ObjectName objGc = null;
try {
objGc = new ObjectName(ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE + ",*");
Set<ObjectName> mbeans = session.getConnection().queryNames(objGc, null);
ObjectName objName = null;
StringBuffer strGcCount = new StringBuffer(512);
if (mbeans != null) {
Iterator<ObjectName> iterator = mbeans.iterator();
while (iterator.hasNext()) {
objName = (ObjectName) iterator.next();
String objGCName = session.getStringAttribute(objName, "Name");
String objGCCount = session.getStringAttribute(objName, "CollectionCount");
String objGCTime = session.getStringAttribute(objName, "CollectionTime");
strGcCount.append(objGCName).append(":").append(objGCCount).append(",");
Object[] objGC = (Object[]) session.getAttribute(objName, "MemoryPoolNames");
for (int i = 0; i < objGC.length; i++) {
if (objGCMap.get(objGC[i].toString()) == null) {
objGCMap.put(objGC[i].toString(), new String[] { objGCName, objGCTime });
} else {
String strTempName = objGCMap.get(objGC[i].toString())[0] + "," + objGCName;
String strTempTime = objGCMap.get(objGC[i].toString())[1] + "," + objGCCount;
objGCMap.put(objGC[i].toString(), new String[] { strTempName, strTempTime });
}
}
}
if (strGcCount.length() > 0) {
strGcCount.deleteCharAt(strGcCount.length() - 1);
}
objVO.setJvmMemGcCount(strGcCount.toString());
}
} catch (Exception e) {
LOGGER.error("獲取GC資訊時出錯" + e.getMessage());
return null;
}
return objGCMap;
}
/**
* 獲取JVM擴充套件資訊
*
* @param objJVM
*/
public void getJVMExtendsInfo(JVMInformationVO objJVM) {
List<JVMDetailVO> lstJVMDetail = new ArrayList<JVMDetailVO>(10);
try {
/***************** JVM版本 ****************/
ObjectName objName = new ObjectName("java.lang:type=Runtime");
String strVMName = jmxSession.getStringAttribute(objName, "VmName");
String strVMVersion = jmxSession.getStringAttribute(objName, "VmVersion");
objJVM.setJvmVersion(strVMName + strVMVersion);
String strJVMArg =
JMXTransformHelp.transformArrayToString(jmxSession.getAttribute(objName, "InputArguments"));
strJVMArg = strJVMArg != null && strJVMArg.length() > 2000 ? strJVMArg.substring(0, 1999) : strJVMArg;
objJVM.setJvmArguments(strJVMArg);
/***************** 記憶體回收情況 ****************/
Map<String, String[]> objGCMap = this.getGCInfo(JMXConstonts.GC_STRATEGY, jmxSession, objJVM);
/***************** 記憶體分割槽情況 ****************/
ObjectName poolName = null;
try {
poolName = new ObjectName(MEMORY_POOL_MXBEAN_DOMAIN_TYPE + ",*");
} catch (MalformedObjectNameException e) {
}
Set<ObjectName> mbeans = jmxSession.getConnection().queryNames(poolName, null);
if (mbeans != null) {
Iterator<ObjectName> iterator = mbeans.iterator();
JVMDetailVO objDetailVO = null;
while (iterator.hasNext()) {
objDetailVO = new JVMDetailVO();
objName = (ObjectName) iterator.next();
MemoryUsage objUsage =
MemoryUsage.from((CompositeDataSupport) jmxSession.getAttribute(objName, "Usage"));
objDetailVO.setJvmDetailId(CommonUtils.getUUID());
objDetailVO.setJvmId(objJVM.getJvmId());
if (objUsage != null) {
objDetailVO.setJvmMemCommitted(objUsage.getCommitted());
objDetailVO.setJvmMemInit(objUsage.getInit());
objDetailVO.setJvmMemMax(objUsage.getMax());
objDetailVO.setJvmMemUsed(objUsage.getUsed());
}
objDetailVO.setJvmMemName(jmxSession.getStringAttribute(objName, "Name"));
objDetailVO.setJvmMemType(jmxSession.getStringAttribute(objName, "Type"));
if (objGCMap.get(objDetailVO.getJvmMemName()) != null) {
objDetailVO.setJvmMemGcStrategy(objGCMap.get(objDetailVO.getJvmMemName())[0]);
objDetailVO.setJvmMemGcTime(objGCMap.get(objDetailVO.getJvmMemName())[1]);
}
lstJVMDetail.add(objDetailVO);
}
}
objJVM.setDetail(lstJVMDetail);
} catch (Exception e) {
LOGGER.error("獲取JVM擴充套件資訊出錯" + e.getMessage());
}
}
4、執行緒佇列資訊
public ThreadInformationVO getThreadQueueInfomation() {
ThreadInformationVO objThreadQueue = new ThreadInformationVO();
// 執行緒物件
ObjectName objThreadPool = null;
try {
String strThreadId = CommonUtils.getUUID();
objThreadPool = (ObjectName) jmxSession.getAttribute(serverRuntime, "ThreadPoolRuntime");
// 執行緒吞吐量
objThreadQueue.setThroughput(jmxSession.getStringAttribute(objThreadPool, "Throughput"));
// 佇列長度
objThreadQueue.setQueueLength(jmxSession.getIntAttribute(objThreadPool, "QueueLength"));
// 執行執行緒總數
objThreadQueue.setExeThreadTotalCount(jmxSession.getIntAttribute(objThreadPool, "ExecuteThreadTotalCount"));
// 待命的執行緒數
objThreadQueue.setStandbyThreadCount(jmxSession.getIntAttribute(objThreadPool, "StandbyThreadCount"));
// 活動執行緒數
objThreadQueue.setActiveExeThreadCount(objThreadQueue.getExeThreadTotalCount()
- objThreadQueue.getStandbyThreadCount());
HealthState objState = (HealthState) jmxSession.getAttribute(objThreadPool, "HealthState");
objThreadQueue.setHealth(String.valueOf(objState.getState()));
// 等待的使用者請求數
objThreadQueue.setPendingRequestCount(jmxSession.getIntAttribute(objThreadPool, "PendingUserRequestCount"));
// 佔用的執行緒數
objThreadQueue.setHoggingThreadsCount(jmxSession.getIntAttribute(objThreadPool, "HoggingThreadCount"));
objThreadQueue.setCreateDate(currentTime);
objThreadQueue.setNodeId(jmxSession.getNodeInfoVO().getNodeInfoId());
objThreadQueue.setThreadId(strThreadId);
/**************** get stuck threads ******/
ExecuteThread[] objExecuteThreadsList =
(ExecuteThread[]) jmxSession.getAttribute(objThreadPool, "ExecuteThreads");
if (objExecuteThreadsList == null || objExecuteThreadsList.length == 0) {
objThreadQueue.setStuckThreadsCount(0);
return objThreadQueue;
}
List<ThreadDetailVO> lstStuckDetail = getStuckThreadList(objExecuteThreadsList, strThreadId);
objThreadQueue.setDetail(lstStuckDetail);
objThreadQueue.setStuckThreadsCount(lstStuckDetail.size());
} catch (Exception e) {
LOGGER.error("採集執行緒佇列時出錯" + e.getMessage());
return null;
}
return objThreadQueue;
}
/**
* 獲取程序ID
*
* @return strPID
*/
/**
* 獲取stuck執行緒
*
* @param objExecuteThreadsList
* @param threadId
* @return List<ThreadDetailVO>
*/
private List<ThreadDetailVO> getStuckThreadList(ExecuteThread[] objExecuteThreadsList, String threadId) {
List<ThreadDetailVO> lstDetail = new ArrayList<ThreadDetailVO>();
ExecuteThread objThread = null;
String strName = null; // 執行緒名稱
// 當前請求的request內容
String strCurrentRequest = "";
String strIsStuck = null; // 是否阻塞
boolean bIsStuck = false;
ThreadDetailVO objDetail = null;
StackTraceElement[] strThreadInfo = null;
StringBuilder strStackTrace = null;
for (int i = 0; i < objExecuteThreadsList.length; i++) {
objThread = objExecuteThreadsList[i];
strIsStuck = String.valueOf(objThread.isStuck());
bIsStuck = strIsStuck != null ? Boolean.parseBoolean(strIsStuck) : false;
if (bIsStuck) {
strName = objThread.getName();
objDetail = new ThreadDetailVO();
objDetail.setThreadName(strName != null ? strName : "");
strCurrentRequest = objThread.getCurrentRequest();
if (strCurrentRequest != null && strCurrentRequest.length() > 4000) {
strCurrentRequest = strCurrentRequest.substring(0, 4000);
}
objDetail.setCurrentRequest(strCurrentRequest);
objDetail.setCurrentRequestUri(JMXTransformHelp.getCurrentRequestUrlFromThread(strCurrentRequest));
objDetail.setThreadExeTime(System.currentTimeMillis() - objThread.getCurrentRequestStartTime());
// 執行緒堆疊資訊
if (objThread.getExecuteThread() != null) {
strThreadInfo = objThread.getExecuteThread().getStackTrace();
}
strStackTrace = new StringBuilder(1024);
if (strThreadInfo != null) {
for (final StackTraceElement stackTraceElement : strThreadInfo) {
strStackTrace.append(JMXTransformHelp.htmlEncode(stackTraceElement.toString(), true)).append(
"<br/>");
}
}
objDetail.setStackInfo(strStackTrace.toString());
objDetail.setDetailId(CommonUtils.getUUID());
objDetail.setThreadId(threadId);
lstDetail.add(objDetail);
}
}
return lstDetail;
}
5、JMS資訊
public JmsInformationVO getJmsInfomation() {
JmsInformationVO objJmsInfo = new JmsInformationVO();
ObjectName objName = (ObjectName) jmxSession.getAttribute(serverRuntime, "JMSRuntime");
objJmsInfo.setJmsId(CommonUtils.getUUID());
objJmsInfo.setServiceNodeId(jmxSession.getNodeInfoVO().getNodeInfoId());
objJmsInfo.setCreateDate(currentTime);
objJmsInfo.setConnectionsCurrentCount(jmxSession.getIntAttribute(objName, "ConnectionsCurrentCount"));
objJmsInfo.setConnectionsHighCount(jmxSession.getIntAttribute(objName, "ConnectionsHighCount"));
objJmsInfo.setConnectionsTotalCount(jmxSession.getIntAttribute(objName, "ConnectionsTotalCount"));
objJmsInfo.setServersCurrentCount(jmxSession.getIntAttribute(objName, "JMSServersCurrentCount"));
objJmsInfo.setServersHighCount(jmxSession.getIntAttribute(objName, "JMSServersHighCount"));
objJmsInfo.setServersTotalCount(jmxSession.getIntAttribute(objName, "JMSServersTotalCount"));
HealthState objState = (HealthState) jmxSession.getAttribute(objName, "HealthState");
objJmsInfo.setHealthState(String.valueOf(objState.getState()));
ObjectName[] objServers = (ObjectName[]) jmxSession.getAttribute(objName, "JMSServers");
if (objServers != null) {
List<JmsDetailVO> lstJmsDetailVO = new ArrayList<JmsDetailVO>();
JmsDetailVO objDetail = null;
for (int i = 0; i < objServers.length; i++) {
objDetail = new JmsDetailVO();
objDetail.setJmsId(objJmsInfo.getJmsId());
objDetail.setJmsDetailId(CommonUtils.getUUID());
objDetail.setJmsName(jmxSession.getStringAttribute(objServers[i], "Name"));
objDetail.setBytesCurrentCount(jmxSession.getIntAttribute(objServers[i], "BytesCurrentCount"));
objDetail.setBytesHighCount(jmxSession.getIntAttribute(objServers[i], "BytesHighCount"));
objDetail.setBytesPendingCount(jmxSession.getIntAttribute(objServers[i], "BytesPendingCount"));
objDetail.setBytesReceivedCount(jmxSession.getIntAttribute(objServers[i], "BytesReceivedCount"));
objDetail.setDestinationsCurrentCount(jmxSession.getIntAttribute(objServers[i],
"DestinationsCurrentCount"));
objDetail.setDestinationsHighCount(jmxSession.getIntAttribute(objServers[i], "DestinationsHighCount"));
objDetail
.setDestinationsTotalCount(jmxSession.getIntAttribute(objServers[i], "DestinationsTotalCount"));
objDetail.setMessagesCurrentCount(jmxSession.getIntAttribute(objServers[i], "MessagesCurrentCount"));
objDetail.setMessagesHighCount(jmxSession.getIntAttribute(objServers[i], "MessagesHighCount"));
objDetail.setMessagesPendingCount(jmxSession.getIntAttribute(objServers[i], "MessagesPendingCount"));
objDetail.setMessagesReceivedCount(jmxSession.getIntAttribute(objServers[i], "MessagesReceivedCount"));
objDetail.setSessionPoolsCurrentCount(jmxSession.getIntAttribute(objServers[i],
"SessionPoolsCurrentCount"));
objDetail.setSessionPoolsHighCount(jmxSession.getIntAttribute(objServers[i], "SessionPoolsHighCount"));
objDetail
.setSessionPoolsTotalCount(jmxSession.getIntAttribute(objServers[i], "SessionPoolsTotalCount"));
objState = (HealthState) jmxSession.getAttribute(objName, "HealthState");
objDetail.setHealthState(String.valueOf(objState.getState()));
lstJmsDetailVO.add(objDetail);
}
objJmsInfo.setLstDetail(lstJmsDetailVO);
}
return objJmsInfo;
}
6、獲取EJB資訊
public List<EjbInformationVO> getEjbInformation() {
List<EjbInformationVO> lstEjb = new ArrayList<EjbInformationVO>();
for (int i = 4; i < applicationRuntimes.length; i++) {
ObjectName[] objComponent =
(ObjectName[]) jmxSession.getAttribute(applicationRuntimes[i], "ComponentRuntimes");
if (objComponent == null) {
continue;
}
for (int j = 0; j < objComponent.length; j++) {
if (objComponent[j] == null || !objComponent[j].getKeyPropertyListString().contains("EJB")) {
continue;
}
ObjectName[] objEjbRuntime = (ObjectName[]) jmxSession.getAttribute(objComponent[j], "EJBRuntimes");
if (objEjbRuntime == null) {
continue;
}
for (int k = 0; k < objEjbRuntime.length; k++) {
EjbInformationVO objEjbVO = new EjbInformationVO();
objEjbVO.setServiceNodeId(jmxSession.getNodeInfoVO().getNodeInfoId());
objEjbVO.setStatus(jmxSession.getStringAttribute(objEjbRuntime[k], "DeploymentState"));
objEjbVO.setEjbId(CommonUtils.getUUID());
objEjbVO.setCreateDate(currentTime);
objEjbVO.setEjbName(jmxSession.getStringAttribute(objEjbRuntime[k], "EJBName"));
ObjectName objEntry = objEjbRuntime[k];
ObjectName objRuntime = (ObjectName) jmxSession.getAttribute(objEntry, "PoolRuntime");
if (objRuntime == null) {
continue;
}
double dDestroyedTotalCount = jmxSession.getDoubleAttribute(objRuntime, "DestroyedTotalCount");
double dMissTotalCount = jmxSession.getDoubleAttribute(objRuntime, "MissTotalCount");
double dAccessTotalCount = jmxSession.getDoubleAttribute(objRuntime, "AccessTotalCount");
double dTimeoutTotalCount = jmxSession.getDoubleAttribute(objRuntime, "TimeoutTotalCount");
// 已破壞 Bean 比率
objEjbVO.setDestroyedBeanRatio(CommonUtils.divideDataToString(dDestroyedTotalCount,
dAccessTotalCount, 2));
// 緩衝池丟失比率
objEjbVO.setCachePoolMissRatio(CommonUtils
.divideDataToString(dMissTotalCount, dAccessTotalCount, 2));
// 緩衝池超時比率
objEjbVO.setCachePoolTimeoutRatio(CommonUtils.divideDataToString(dTimeoutTotalCount,
dAccessTotalCount, 2));
// objRuntime = (ObjectName) jmxSession.getAttribute(objEntry, "CacheRuntime");
// // 快取丟失比率 =(快取丟失總數/快取訪問總數)* 100
// double dCacheMissCount = jmxSession.getDoubleAttribute(objRuntime, "CacheMissCount");
// double dActivationCount = jmxSession.getDoubleAttribute(objRuntime, "ActivationCount");
// objEjbVO.setCachedMissRatio(CommonUtils.divideDataToString(dCacheMissCount, dActivationCount,
// 2));
// objRuntime = (ObjectName) jmxSession.getAttribute(objEntry, "LockingRuntime");
// // 鎖定等待程式比率
// // Lock Timeout Ratio =(Lock Manager Timeout Total Count / Lock Manager Total Access Count) * 100
// double dWaiterCurrentCount = jmxSession.getDoubleAttribute(objRuntime, "WaiterCurrentCount");
// double dLockCurrentCount = jmxSession.getDoubleAttribute(objRuntime, "LockEntriesCurrentCount");
// objEjbVO.setLockWaitRatio(CommonUtils.divideDataToString(dWaiterCurrentCount, dLockCurrentCount,
// 2));
// // Lock Timeout Ratio =(Lock Manager Timeout Total Count / Lock Manager Total Access Count) * 100
// // 鎖定超時比率
// double dLockManagerAccessCount = jmxSession.getDoubleAttribute(objRuntime,
// "LockManagerAccessCount");
// dTimeoutTotalCount = jmxSession.getDoubleAttribute(objRuntime, "TimeoutTotalCount");
// objEjbVO.setLockTimeoutRatio(CommonUtils.divideDataToString(dTimeoutTotalCount,
// dLockManagerAccessCount, 2));
//
objRuntime = (ObjectName) jmxSession.getAttribute(objEntry, "TransactionRuntime");
double dTranCommTotalCount =
jmxSession.getDoubleAttribute(objRuntime, "TransactionsCommittedTotalCount");
double dTranRollBackCount =
jmxSession.getDoubleAttribute(objRuntime, "TransactionsRolledBackTotalCount");
double dTranTimeOutTotalCount =
jmxSession.getDoubleAttribute(objRuntime, "TransactionsTimedOutTotalCount");
// 事務回滾比率
objEjbVO.setTransactionRollBackRatio(CommonUtils.divideDataToString(dTranRollBackCount,
dTranCommTotalCount, 2));
// 事務超時比率
objEjbVO.setTransactionTimeoutRatio(CommonUtils.divideDataToString(dTranTimeOutTotalCount,
dTranCommTotalCount, 2));
lstEjb.add(objEjbVO);
}
}
}
return lstEjb;
}
如果還有其他需求可以檢視http://edocs.weblogicfans.net/wls/docs92/jmx/index.html