1、JMX簡介html
JMX是一種JAVA的正式規範,它主要目的是讓程序有被管理的功能,那麼怎麼理解所謂的「被管理」呢?試想你開發了一個軟件(如WEB網站),它是在24小時不間斷運行的,那麼你可能會想要「監控」這個軟件的運行狀況,好比收到了多少數據,有多少人登陸等等。或者你又想「配置」這個軟件,好比如今訪問人數比較多,你想把數據鏈接池設置得大一些。java
固然,你也許會專門爲這些管理來開發軟件,但若是你藉助JMX,則會發現建立這樣的管理程序是如此簡單。由於你無需爲管理程序來開發界面,已經有通用的JMX管理軟件,如MC4J,或者是用通常都附帶提供的HTML網頁來管理,你要作的僅僅是將本身要被管理和監控類的按照JMX規範修改一下便可。web
中間件軟件WebLogic的管理頁面就是基於JMX開發的,而JBoss則整個系統都基於JMX構架。緩存
2、監控Weblogicsession
weblogic配置app
1. 首先是要配置WebLogic的啓動腳本。dom
D:\weblogic\domains\cebbch_domain\bin\startWebLogic.cmd jvm
在其中找到ide
set JAVA_OPTIONS=%SAVE_JAVA_OPTIONS%後,添加一句話,變成:函數
set JAVA_OPTIONS=%JAVA_OPTIONS% -Dcom.sun.management.jmxremote.port=9999
set JAVA_OPTIONS=%JAVA_OPTIONS% -Dcom.sun.management.jmxremote.ssl=false
set JAVA_OPTIONS=%JAVA_OPTIONS% -Dcom.sun.management.jmxremote.authenticate=false
注:
1. -Dcom.sun.management.jmxremote.port :這個是配置遠程 connection 的端口號的,要肯定這個端口沒有被佔用
2. -Dcom.sun.management.jmxremote.ssl=false 指定了 JMX 是否啓用 ssl
3. -Dcom.sun.management.jmxremote.authenticate=false 指定了JMX 是否啓用鑑權(須要用戶名,密碼鑑權)
4. -Djava.rmi.server.hostname :這個是配置 server 的 IP 的
下面介紹下如何經過jmx獲取監控信息。
一、服務基本信息信息
[java] view plain copy
- /**
- * 構造函數
- */
- 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;
- }
二、JDBC信息
[java] view plain copy
- 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;
- }
-
三、JVM內存信息以及GC信息
[java] view plain copy
- 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;
- }
[java] view plain copy
- /**
- * 獲取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());
- }
- }
四、線程隊列信息
[java] view plain copy
- 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;
- }
五、JMS信息
[java] view plain copy
- 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;
- }
-
六、獲取EJB信息
[java] view plain copy
- 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;
- }