通过JMX监控weblogic服务

一、JMX简介

  JMX是一种JAVA的正式规范,它主要目的是让程序有被管理的功能,那么怎么理解所谓的“被管理”呢?试想你开发了一个软件(如WEB网站),它是在24小时不间断运行的,那么你可能会想要“监控”这个软件的运行情况,比如收到了多少数据,有多少人登录等等。或者你又想“配置”这个软件,比如现在访问人数比较多,你想把数据连接池设置得大一些。

  当然,你也许会专门为这些管理来开发软件,但如果你借助JMX,则会发现创建这样的管理程序是如此简单。因为你无需为管理程序来开发界面,已经有通用的JMX管理软件,如MC4J,或者是用一般都附带提供的HTML网页来管理,你要做的仅仅是将自己要被管理和监控类的按照JMX规范修改一下即可。

  中间件软件WebLogic的管理页面就是基于JMX开发的,而JBoss则整个系统都基于JMX构架。

 二、监控Weblogic

weblogic配置

1. 首先是要配置WebLogic的启动脚本。

D:\weblogic\domains\cebbch_domain\bin\startWebLogic.cmd 

在其中找到

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获取监控信息。

1、服务基本信息信息

 

[java] view plain copy

  1. /** 
  2.     * 构造函数 
  3.     */  
  4.    public WebLogicMiddlewareAdapter(JMXSession jmxSession) {  
  5.        currentTime = CommonUtils.getCurrentTime();  
  6.        this.jmxSession = jmxSession;  
  7.        serverRuntime = (ObjectName) jmxSession.getAttribute(runtimeService, "ServerRuntime");  
  8.        applicationRuntimes = (ObjectName[]) jmxSession.getAttribute(serverRuntime, "ApplicationRuntimes");  
  9.    }  
  10.      
  11.    /** 
  12.     * @see com.comtop.numen.monitor.collection.appservice.middleware.adapter.MiddlewareAdapter#getMiddleWareBaseInfomation() 
  13.     */  
  14.    @Override  
  15.    public MiddleWareBaseInfoVO getMiddleWareBaseInfomation() {  
  16.        MiddleWareBaseInfoVO objWebLogic = new MiddleWareBaseInfoVO();  
  17.        try {  
  18.            objWebLogic.setMiddlewareId(CommonUtils.getUUID());  
  19.            objWebLogic.setWebContext(this.getWebConext());  
  20.            if (JMXConstonts.JMX_COLLECT_EXTENDS.equals(jmxSession.getNodeInfoVO().getIsJmxExtends())) {  
  21.                // 获取进程ID  
  22.                objWebLogic.setMiddleWarePid(getMiddlewarePID());  
  23.            }  
  24.            // 服务名称  
  25.            objWebLogic.setServerName(jmxSession.getStringAttribute(runtimeService, "ServerName"));  
  26.            // Domain名称  
  27.            ObjectName objConfig = (ObjectName) jmxSession.getAttribute(runtimeService, "DomainConfiguration");  
  28.            objWebLogic.setDomainName(jmxSession.getStringAttribute(objConfig, "Name"));  
  29.            String strWLVersion=jmxSession.getStringAttribute(serverRuntime, "WeblogicVersion");  
  30.            strWLVersion=strWLVersion.substring(strWLVersion.lastIndexOf("WebLogic"), strWLVersion.length()-1);  
  31.            objWebLogic.setRunnningState(jmxSession.getStringAttribute(serverRuntime, "State"));  
  32.            objWebLogic.setListenAddress(jmxSession.getStringAttribute(serverRuntime, "ListenAddress"));  
  33.            objWebLogic.setListenPort(jmxSession.getStringAttribute(serverRuntime, "ListenPort"));  
  34.            objWebLogic.setAdminServerHost(jmxSession.getStringAttribute(serverRuntime, "AdminServerHost"));  
  35.            objWebLogic.setAdminServerListenPort(jmxSession.getStringAttribute(serverRuntime, "AdminServerListenPort"));  
  36.            objWebLogic.setAdministrationPort(jmxSession.getStringAttribute(serverRuntime, "AdministrationPort"));  
  37.            objWebLogic  
  38.                .setOpenSocketsCurrentCount(jmxSession.getIntAttribute(serverRuntime, "OpenSocketsCurrentCount"));  
  39.            objWebLogic  
  40.                .setSocketsOpenedTotalCount(jmxSession.getIntAttribute(serverRuntime, "SocketsOpenedTotalCount"));  
  41.            objWebLogic.setRestartsTotalCount(jmxSession.getIntAttribute(serverRuntime, "RestartsTotalCount"));  
  42.            objWebLogic.setSSLListenAddress(jmxSession.getStringAttribute(serverRuntime, "SSLListenAddress"));  
  43.            long lTime = (Long) jmxSession.getAttribute(serverRuntime, "ActivationTime");  
  44.           
  45.        } catch (Exception e) {  
  46.            LOGGER.error("采集WebLogic信息出错" + e.getMessage());  
  47.            return null;  
  48.        }  
  49.        return objWebLogic;  
  50.    }  

 

 

 

2、JDBC信息

 

[java] view plain copy

  1. public JDBCInformationVO getJDBCInfomation() {  
  2.        JDBCInformationVO objJDBC = new JDBCInformationVO();  
  3.        try {  
  4.            List<JDBCDetailVO> lstJdbcDetail = new ArrayList<JDBCDetailVO>();  
  5.            List<JDBCInformationVO> lstJdbc = new ArrayList<JDBCInformationVO>();  
  6.            String strJdbcId = CommonUtils.getUUID();  
  7.            // 获取域配置对象  
  8.            ObjectName domainConfig = (ObjectName) jmxSession.getAttribute(runtimeService, "DomainConfiguration");  
  9.            ObjectName[] objJDBCSystemResources =  
  10.                (ObjectName[]) jmxSession.getAttribute(domainConfig, "JDBCSystemResources");  
  11.            ObjectName jdbcSRName = (ObjectName) jmxSession.getAttribute(serverRuntime, "JDBCServiceRuntime");  
  12.            ObjectName[] objJDBCDataSource =  
  13.                (ObjectName[]) jmxSession.getAttribute(jdbcSRName, "JDBCDataSourceRuntimeMBeans");  
  14.            // 定义jdbcUtils对象  
  15.            JDBCDetailVO objJDBCdetail = null;  
  16.            ObjectName objJdbcResource = null;  
  17.            ObjectName objPoolPrms = null;  
  18.            for (int i = 0; i < objJDBCDataSource.length; i++) {  
  19.                objJDBCdetail = new JDBCDetailVO();  
  20.                objJDBCdetail.setDetailId(CommonUtils.getUUID());  
  21.                objJDBCdetail.setJdbcId(strJdbcId);  
  22.                // 判断JDBCSystemResources对象是否为null  
  23.                if (objJDBCSystemResources[i] != null) {  
  24.                    objJdbcResource = (ObjectName) jmxSession.getAttribute(objJDBCSystemResources[i], "JDBCResource");  
  25.                    objPoolPrms = (ObjectName) jmxSession.getAttribute(objJdbcResource, "JDBCConnectionPoolParams");  
  26.                    // 总的连接数  
  27.                    objJDBCdetail.setMaxCapacity(jmxSession.getIntAttribute(objPoolPrms, "MaxCapacity"));  
  28.                    objJDBCdetail.setIncreseCapacity(jmxSession.getIntAttribute(objPoolPrms, "CapacityIncrement"));  
  29.                    objJDBCdetail.setInitCapacity(jmxSession.getIntAttribute(objPoolPrms, "InitialCapacity"));  
  30.                    // 数据源名称  
  31.                    String objDataSourceName = this.getJndiName(objJdbcResource);  
  32.                    if (objDataSourceName == null) {  
  33.                        break;  
  34.                    }  
  35.                    objJDBCdetail.setDataSourceName(objDataSourceName);  
  36.                }  
  37.                // 最大历史的连接数  
  38.                objJDBCdetail.setHisMaxConn(jmxSession.getIntAttribute(objJDBCDataSource[i],  
  39.                    "ActiveConnectionsHighCount"));  
  40.                // 驱动版本  
  41.                objJDBCdetail.setDriverName(jmxSession.getStringAttribute(objJDBCDataSource[i], "VersionJDBCDriver"));  
  42.                // 数据源状态  
  43.                objJDBCdetail.setDataSourceState(jmxSession.getStringAttribute(objJDBCDataSource[i], "State"));  
  44.                // 当前容量  
  45.                objJDBCdetail.setCurrCapacity(jmxSession.getIntAttribute(objJDBCDataSource[i], "CurrCapacity"));  
  46.                // 当前活动的连接数  
  47.                objJDBCdetail.setCurrConnection(jmxSession.getIntAttribute(objJDBCDataSource[i],  
  48.                    "ActiveConnectionsCurrentCount"));  
  49.                // 数据源泄漏的连接数  
  50.                objJDBCdetail.setLeakConn(jmxSession.getIntAttribute(objJDBCDataSource[i], "LeakedConnectionCount"));  
  51.                // 当前等待连接数  
  52.                objJDBCdetail.setCurrWaitConn(jmxSession.getIntAttribute(objJDBCDataSource[i],  
  53.                    "WaitingForConnectionCurrentCount"));  
  54.                // 历史等待连接数  
  55.                objJDBCdetail.setHisMaxWaitConn(jmxSession.getIntAttribute(objJDBCDataSource[i],  
  56.                    "WaitingForConnectionTotal"));  
  57.                // 当前可用连接数  
  58.                objJDBCdetail.setCurrVailableConn(jmxSession.getIntAttribute(objJDBCDataSource[i], "NumAvailable"));  
  59.                // 失败重连数  
  60.                objJDBCdetail.setFailReConn(jmxSession  
  61.                    .getIntAttribute(objJDBCDataSource[i], "FailuresToReconnectCount"));  
  62.            }  
  63.            objJDBC.setDetail(lstJdbcDetail);  
  64.            objJDBC.setJdbcInfo(lstJdbc);  
  65.        } catch (Exception e) {  
  66.            LOGGER.error("采集JDBC信息出错" + e.getMessage());  
  67.            return null;  
  68.        }  
  69.        return objJDBC;  
  70.    }  
  71.      

 

 

3、JVM内存信息以及GC信息

 

 

[java] view plain copy

  1. public JVMInformationVO getJVMInfomation() {  
  2.         JVMInformationVO objJVM = new JVMInformationVO();  
  3.         try {  
  4.             objJVM.setJvmId(CommonUtils.getUUID());  
  5.             ObjectName objName = (ObjectName) jmxSession.getAttribute(serverRuntime, "JVMRuntime");  
  6.             // jvm 内存使用情况  
  7.             double memoryMaxSize =  
  8.                 Double.parseDouble(String.valueOf(jmxSession.getAttribute(objName, "HeapSizeCurrent")));  
  9.             double memoryFreeSize =  
  10.                 Double.parseDouble(String.valueOf(jmxSession.getAttribute(objName, "HeapFreeCurrent")));  
  11.             // double memoryPer = (memoryMaxSize - memoryFreeSize) / memoryMaxSize * 100;  
  12.             objJVM.setJvmHeapTotalSize(String.valueOf(CommonUtils.getDoubleToPattern(memoryMaxSize, 2)));  
  13.             objJVM.setJvmHeapUsedSize(String.valueOf(CommonUtils  
  14.                 .getDoubleToPattern((memoryMaxSize - memoryFreeSize), 2)));  
  15.             objJVM.setCreateDate(currentTime);  
  16.             objJVM.setNodeId(jmxSession.getNodeInfoVO().getNodeInfoId());  
  17.             objName = (ObjectName) jmxSession.getAttribute(serverRuntime, "JVMRuntime");  
  18.             objJVM.setJavaVersion(jmxSession.getStringAttribute(objName, "JavaVersion"));  
  19.             objJVM.setRunningState(jmxSession.getStringAttribute(serverRuntime, "State"));  
  20.             objJVM.setNodeInfoVO(jmxSession.getNodeInfoVO());  
  21.             /************************************** 
  22.              * 采集扩展信息 
  23.              ************************************/  
  24.             if (JMXConstonts.JMX_COLLECT_EXTENDS.equals(jmxSession.getNodeInfoVO().getIsJmxExtends())) {  
  25.                 this.getJVMExtendsInfo(objJVM);  
  26.             }  
  27.         } catch (Exception e) {  
  28.             LOGGER.error("采集JVM内存信息时出错" + e.getMessage());  
  29.             return null;  
  30.         }  
  31.         return objJVM;  
  32.     }  
  33.       
  34.     /** 
  35.      * 获取GC信息 
  36.      *  
  37.      * @param strName 
  38.      * @param session 
  39.      * @param objVO 
  40.      * @return 
  41.      */  
  42.     public Map<String, String[]> getGCInfo(String[] strName, JMXSession session, JVMInformationVO objVO) {  
  43.         Map<String, String[]> objGCMap = new HashMap<String, String[]>(5);  
  44.         ObjectName objGc = null;  
  45.         try {  
  46.             objGc = new ObjectName(ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE + ",*");  
  47.             Set<ObjectName> mbeans = session.getConnection().queryNames(objGc, null);  
  48.             ObjectName objName = null;  
  49.             StringBuffer strGcCount = new StringBuffer(512);  
  50.             if (mbeans != null) {  
  51.                 Iterator<ObjectName> iterator = mbeans.iterator();  
  52.                 while (iterator.hasNext()) {  
  53.                     objName = (ObjectName) iterator.next();  
  54.                     String objGCName = session.getStringAttribute(objName, "Name");  
  55.                     String objGCCount = session.getStringAttribute(objName, "CollectionCount");  
  56.                     String objGCTime = session.getStringAttribute(objName, "CollectionTime");  
  57.                     strGcCount.append(objGCName).append(":").append(objGCCount).append(",");  
  58.                     Object[] objGC = (Object[]) session.getAttribute(objName, "MemoryPoolNames");  
  59.                     for (int i = 0; i < objGC.length; i++) {  
  60.                         if (objGCMap.get(objGC[i].toString()) == null) {  
  61.                             objGCMap.put(objGC[i].toString(), new String[] { objGCName, objGCTime });  
  62.                         } else {  
  63.                             String strTempName = objGCMap.get(objGC[i].toString())[0] + "," + objGCName;  
  64.                             String strTempTime = objGCMap.get(objGC[i].toString())[1] + "," + objGCCount;  
  65.                             objGCMap.put(objGC[i].toString(), new String[] { strTempName, strTempTime });  
  66.                         }  
  67.                     }  
  68.                 }  
  69.                 if (strGcCount.length() > 0) {  
  70.                     strGcCount.deleteCharAt(strGcCount.length() - 1);  
  71.                 }  
  72.                 objVO.setJvmMemGcCount(strGcCount.toString());  
  73.             }  
  74.         } catch (Exception e) {  
  75.             LOGGER.error("获取GC信息时出错" + e.getMessage());  
  76.             return null;  
  77.         }  
  78.         return objGCMap;  
  79.     }  

 

[java] view plain copy

  1. /** 
  2.  * 获取JVM扩展信息 
  3.  *  
  4.  * @param objJVM 
  5.  */  
  6. public void getJVMExtendsInfo(JVMInformationVO objJVM) {  
  7.     List<JVMDetailVO> lstJVMDetail = new ArrayList<JVMDetailVO>(10);  
  8.     try {  
  9.         /***************** JVM版本 ****************/  
  10.         ObjectName objName = new ObjectName("java.lang:type=Runtime");  
  11.         String strVMName = jmxSession.getStringAttribute(objName, "VmName");  
  12.         String strVMVersion = jmxSession.getStringAttribute(objName, "VmVersion");  
  13.         objJVM.setJvmVersion(strVMName + strVMVersion);  
  14.         String strJVMArg =  
  15.             JMXTransformHelp.transformArrayToString(jmxSession.getAttribute(objName, "InputArguments"));  
  16.         strJVMArg = strJVMArg != null && strJVMArg.length() > 2000 ? strJVMArg.substring(0, 1999) : strJVMArg;  
  17.         objJVM.setJvmArguments(strJVMArg);  
  18.           
  19.         /***************** 内存回收情况 ****************/  
  20.         Map<String, String[]> objGCMap = this.getGCInfo(JMXConstonts.GC_STRATEGY, jmxSession, objJVM);  
  21.           
  22.         /***************** 内存分区情况 ****************/  
  23.         ObjectName poolName = null;  
  24.         try {  
  25.             poolName = new ObjectName(MEMORY_POOL_MXBEAN_DOMAIN_TYPE + ",*");  
  26.         } catch (MalformedObjectNameException e) {  
  27.         }  
  28.         Set<ObjectName> mbeans = jmxSession.getConnection().queryNames(poolName, null);  
  29.         if (mbeans != null) {  
  30.             Iterator<ObjectName> iterator = mbeans.iterator();  
  31.             JVMDetailVO objDetailVO = null;  
  32.             while (iterator.hasNext()) {  
  33.                 objDetailVO = new JVMDetailVO();  
  34.                 objName = (ObjectName) iterator.next();  
  35.                 MemoryUsage objUsage =  
  36.                     MemoryUsage.from((CompositeDataSupport) jmxSession.getAttribute(objName, "Usage"));  
  37.                 objDetailVO.setJvmDetailId(CommonUtils.getUUID());  
  38.                 objDetailVO.setJvmId(objJVM.getJvmId());  
  39.                 if (objUsage != null) {  
  40.                     objDetailVO.setJvmMemCommitted(objUsage.getCommitted());  
  41.                     objDetailVO.setJvmMemInit(objUsage.getInit());  
  42.                     objDetailVO.setJvmMemMax(objUsage.getMax());  
  43.                     objDetailVO.setJvmMemUsed(objUsage.getUsed());  
  44.                 }  
  45.                 objDetailVO.setJvmMemName(jmxSession.getStringAttribute(objName, "Name"));  
  46.                 objDetailVO.setJvmMemType(jmxSession.getStringAttribute(objName, "Type"));  
  47.                 if (objGCMap.get(objDetailVO.getJvmMemName()) != null) {  
  48.                     objDetailVO.setJvmMemGcStrategy(objGCMap.get(objDetailVO.getJvmMemName())[0]);  
  49.                     objDetailVO.setJvmMemGcTime(objGCMap.get(objDetailVO.getJvmMemName())[1]);  
  50.                 }  
  51.                 lstJVMDetail.add(objDetailVO);  
  52.             }  
  53.         }  
  54.         objJVM.setDetail(lstJVMDetail);  
  55.     } catch (Exception e) {  
  56.         LOGGER.error("获取JVM扩展信息出错" + e.getMessage());  
  57.     }  
  58. }  

 

 

 

4、线程队列信息

 

[java] view plain copy

  1. public ThreadInformationVO getThreadQueueInfomation() {  
  2.        ThreadInformationVO objThreadQueue = new ThreadInformationVO();  
  3.        // 线程对象  
  4.        ObjectName objThreadPool = null;  
  5.        try {  
  6.            String strThreadId = CommonUtils.getUUID();  
  7.            objThreadPool = (ObjectName) jmxSession.getAttribute(serverRuntime, "ThreadPoolRuntime");  
  8.            // 线程吞吐量  
  9.            objThreadQueue.setThroughput(jmxSession.getStringAttribute(objThreadPool, "Throughput"));  
  10.            // 队列长度  
  11.            objThreadQueue.setQueueLength(jmxSession.getIntAttribute(objThreadPool, "QueueLength"));  
  12.            // 执行线程总数  
  13.            objThreadQueue.setExeThreadTotalCount(jmxSession.getIntAttribute(objThreadPool, "ExecuteThreadTotalCount"));  
  14.            // 待命的线程数  
  15.            objThreadQueue.setStandbyThreadCount(jmxSession.getIntAttribute(objThreadPool, "StandbyThreadCount"));  
  16.            // 活动线程数  
  17.            objThreadQueue.setActiveExeThreadCount(objThreadQueue.getExeThreadTotalCount()  
  18.                - objThreadQueue.getStandbyThreadCount());  
  19.            HealthState objState = (HealthState) jmxSession.getAttribute(objThreadPool, "HealthState");  
  20.            objThreadQueue.setHealth(String.valueOf(objState.getState()));  
  21.            // 等待的用户请求数  
  22.            objThreadQueue.setPendingRequestCount(jmxSession.getIntAttribute(objThreadPool, "PendingUserRequestCount"));  
  23.            // 占用的线程数  
  24.            objThreadQueue.setHoggingThreadsCount(jmxSession.getIntAttribute(objThreadPool, "HoggingThreadCount"));  
  25.            objThreadQueue.setCreateDate(currentTime);  
  26.            objThreadQueue.setNodeId(jmxSession.getNodeInfoVO().getNodeInfoId());  
  27.            objThreadQueue.setThreadId(strThreadId);  
  28.            /**************** get stuck threads ******/  
  29.            ExecuteThread[] objExecuteThreadsList =  
  30.                (ExecuteThread[]) jmxSession.getAttribute(objThreadPool, "ExecuteThreads");  
  31.            if (objExecuteThreadsList == null || objExecuteThreadsList.length == 0) {  
  32.                objThreadQueue.setStuckThreadsCount(0);  
  33.                return objThreadQueue;  
  34.            }  
  35.            List<ThreadDetailVO> lstStuckDetail = getStuckThreadList(objExecuteThreadsList, strThreadId);  
  36.            objThreadQueue.setDetail(lstStuckDetail);  
  37.            objThreadQueue.setStuckThreadsCount(lstStuckDetail.size());  
  38.        } catch (Exception e) {  
  39.            LOGGER.error("采集线程队列时出错" + e.getMessage());  
  40.            return null;  
  41.        }  
  42.        return objThreadQueue;  
  43.    }  
  44.      
  45.    /** 
  46.     * 获取进程ID 
  47.     *  
  48.     * @return strPID 
  49.     */  
  50.      
  51.    /** 
  52.     * 获取stuck线程 
  53.     *  
  54.     * @param objExecuteThreadsList 
  55.     * @param threadId 
  56.     * @return List<ThreadDetailVO> 
  57.     */  
  58.    private List<ThreadDetailVO> getStuckThreadList(ExecuteThread[] objExecuteThreadsList, String threadId) {  
  59.        List<ThreadDetailVO> lstDetail = new ArrayList<ThreadDetailVO>();  
  60.        ExecuteThread objThread = null;  
  61.        String strName = null; // 线程名称  
  62.        // 当前请求的request内容  
  63.        String strCurrentRequest = "";  
  64.        String strIsStuck = null; // 是否阻塞  
  65.        boolean bIsStuck = false;  
  66.        ThreadDetailVO objDetail = null;  
  67.        StackTraceElement[] strThreadInfo = null;  
  68.        StringBuilder strStackTrace = null;  
  69.        for (int i = 0; i < objExecuteThreadsList.length; i++) {  
  70.            objThread = objExecuteThreadsList[i];  
  71.            strIsStuck = String.valueOf(objThread.isStuck());  
  72.            bIsStuck = strIsStuck != null ? Boolean.parseBoolean(strIsStuck) : false;  
  73.            if (bIsStuck) {  
  74.                strName = objThread.getName();  
  75.                objDetail = new ThreadDetailVO();  
  76.                objDetail.setThreadName(strName != null ? strName : "");  
  77.                strCurrentRequest = objThread.getCurrentRequest();  
  78.                if (strCurrentRequest != null && strCurrentRequest.length() > 4000) {  
  79.                    strCurrentRequest = strCurrentRequest.substring(0, 4000);  
  80.                }  
  81.                objDetail.setCurrentRequest(strCurrentRequest);  
  82.                objDetail.setCurrentRequestUri(JMXTransformHelp.getCurrentRequestUrlFromThread(strCurrentRequest));  
  83.                objDetail.setThreadExeTime(System.currentTimeMillis() - objThread.getCurrentRequestStartTime());  
  84.                // 线程堆栈信息  
  85.                if (objThread.getExecuteThread() != null) {  
  86.                    strThreadInfo = objThread.getExecuteThread().getStackTrace();  
  87.                }  
  88.                strStackTrace = new StringBuilder(1024);  
  89.                if (strThreadInfo != null) {  
  90.                    for (final StackTraceElement stackTraceElement : strThreadInfo) {  
  91.                        strStackTrace.append(JMXTransformHelp.htmlEncode(stackTraceElement.toString(), true)).append(  
  92.                            "<br/>");  
  93.                    }  
  94.                }  
  95.                objDetail.setStackInfo(strStackTrace.toString());  
  96.                objDetail.setDetailId(CommonUtils.getUUID());  
  97.                objDetail.setThreadId(threadId);  
  98.                lstDetail.add(objDetail);  
  99.            }  
  100.        }  
  101.        return lstDetail;  
  102.    }  

 

5、JMS信息

[java] view plain copy

  1. public JmsInformationVO getJmsInfomation() {  
  2.       JmsInformationVO objJmsInfo = new JmsInformationVO();  
  3.       ObjectName objName = (ObjectName) jmxSession.getAttribute(serverRuntime, "JMSRuntime");  
  4.       objJmsInfo.setJmsId(CommonUtils.getUUID());  
  5.       objJmsInfo.setServiceNodeId(jmxSession.getNodeInfoVO().getNodeInfoId());  
  6.       objJmsInfo.setCreateDate(currentTime);  
  7.       objJmsInfo.setConnectionsCurrentCount(jmxSession.getIntAttribute(objName, "ConnectionsCurrentCount"));  
  8.       objJmsInfo.setConnectionsHighCount(jmxSession.getIntAttribute(objName, "ConnectionsHighCount"));  
  9.       objJmsInfo.setConnectionsTotalCount(jmxSession.getIntAttribute(objName, "ConnectionsTotalCount"));  
  10.       objJmsInfo.setServersCurrentCount(jmxSession.getIntAttribute(objName, "JMSServersCurrentCount"));  
  11.       objJmsInfo.setServersHighCount(jmxSession.getIntAttribute(objName, "JMSServersHighCount"));  
  12.       objJmsInfo.setServersTotalCount(jmxSession.getIntAttribute(objName, "JMSServersTotalCount"));  
  13.       HealthState objState = (HealthState) jmxSession.getAttribute(objName, "HealthState");  
  14.       objJmsInfo.setHealthState(String.valueOf(objState.getState()));  
  15.       ObjectName[] objServers = (ObjectName[]) jmxSession.getAttribute(objName, "JMSServers");  
  16.       if (objServers != null) {  
  17.           List<JmsDetailVO> lstJmsDetailVO = new ArrayList<JmsDetailVO>();  
  18.           JmsDetailVO objDetail = null;  
  19.           for (int i = 0; i < objServers.length; i++) {  
  20.               objDetail = new JmsDetailVO();  
  21.               objDetail.setJmsId(objJmsInfo.getJmsId());  
  22.               objDetail.setJmsDetailId(CommonUtils.getUUID());  
  23.               objDetail.setJmsName(jmxSession.getStringAttribute(objServers[i], "Name"));  
  24.               objDetail.setBytesCurrentCount(jmxSession.getIntAttribute(objServers[i], "BytesCurrentCount"));  
  25.               objDetail.setBytesHighCount(jmxSession.getIntAttribute(objServers[i], "BytesHighCount"));  
  26.               objDetail.setBytesPendingCount(jmxSession.getIntAttribute(objServers[i], "BytesPendingCount"));  
  27.               objDetail.setBytesReceivedCount(jmxSession.getIntAttribute(objServers[i], "BytesReceivedCount"));  
  28.               objDetail.setDestinationsCurrentCount(jmxSession.getIntAttribute(objServers[i],  
  29.                   "DestinationsCurrentCount"));  
  30.               objDetail.setDestinationsHighCount(jmxSession.getIntAttribute(objServers[i], "DestinationsHighCount"));  
  31.               objDetail  
  32.                   .setDestinationsTotalCount(jmxSession.getIntAttribute(objServers[i], "DestinationsTotalCount"));  
  33.               objDetail.setMessagesCurrentCount(jmxSession.getIntAttribute(objServers[i], "MessagesCurrentCount"));  
  34.               objDetail.setMessagesHighCount(jmxSession.getIntAttribute(objServers[i], "MessagesHighCount"));  
  35.               objDetail.setMessagesPendingCount(jmxSession.getIntAttribute(objServers[i], "MessagesPendingCount"));  
  36.               objDetail.setMessagesReceivedCount(jmxSession.getIntAttribute(objServers[i], "MessagesReceivedCount"));  
  37.               objDetail.setSessionPoolsCurrentCount(jmxSession.getIntAttribute(objServers[i],  
  38.                   "SessionPoolsCurrentCount"));  
  39.               objDetail.setSessionPoolsHighCount(jmxSession.getIntAttribute(objServers[i], "SessionPoolsHighCount"));  
  40.               objDetail  
  41.                   .setSessionPoolsTotalCount(jmxSession.getIntAttribute(objServers[i], "SessionPoolsTotalCount"));  
  42.               objState = (HealthState) jmxSession.getAttribute(objName, "HealthState");  
  43.               objDetail.setHealthState(String.valueOf(objState.getState()));  
  44.               lstJmsDetailVO.add(objDetail);  
  45.           }  
  46.           objJmsInfo.setLstDetail(lstJmsDetailVO);  
  47.       }  
  48.       return objJmsInfo;  
  49.   }  
  50.     

 6、获取EJB信息

[java] view plain copy

  1. public List<EjbInformationVO> getEjbInformation() {  
  2.     List<EjbInformationVO> lstEjb = new ArrayList<EjbInformationVO>();  
  3.     for (int i = 4; i < applicationRuntimes.length; i++) {  
  4.         ObjectName[] objComponent =  
  5.             (ObjectName[]) jmxSession.getAttribute(applicationRuntimes[i], "ComponentRuntimes");  
  6.         if (objComponent == null) {  
  7.             continue;  
  8.         }  
  9.         for (int j = 0; j < objComponent.length; j++) {  
  10.             if (objComponent[j] == null || !objComponent[j].getKeyPropertyListString().contains("EJB")) {  
  11.                 continue;  
  12.             }  
  13.             ObjectName[] objEjbRuntime = (ObjectName[]) jmxSession.getAttribute(objComponent[j], "EJBRuntimes");  
  14.             if (objEjbRuntime == null) {  
  15.                 continue;  
  16.             }  
  17.             for (int k = 0; k < objEjbRuntime.length; k++) {  
  18.                 EjbInformationVO objEjbVO = new EjbInformationVO();  
  19.                 objEjbVO.setServiceNodeId(jmxSession.getNodeInfoVO().getNodeInfoId());  
  20.                 objEjbVO.setStatus(jmxSession.getStringAttribute(objEjbRuntime[k], "DeploymentState"));  
  21.                 objEjbVO.setEjbId(CommonUtils.getUUID());  
  22.                 objEjbVO.setCreateDate(currentTime);  
  23.                 objEjbVO.setEjbName(jmxSession.getStringAttribute(objEjbRuntime[k], "EJBName"));  
  24.                 ObjectName objEntry = objEjbRuntime[k];  
  25.                   
  26.                 ObjectName objRuntime = (ObjectName) jmxSession.getAttribute(objEntry, "PoolRuntime");  
  27.                 if (objRuntime == null) {  
  28.                     continue;  
  29.                 }  
  30.                 double dDestroyedTotalCount = jmxSession.getDoubleAttribute(objRuntime, "DestroyedTotalCount");  
  31.                 double dMissTotalCount = jmxSession.getDoubleAttribute(objRuntime, "MissTotalCount");  
  32.                 double dAccessTotalCount = jmxSession.getDoubleAttribute(objRuntime, "AccessTotalCount");  
  33.                 double dTimeoutTotalCount = jmxSession.getDoubleAttribute(objRuntime, "TimeoutTotalCount");  
  34.                 // 已破坏 Bean 比率  
  35.                 objEjbVO.setDestroyedBeanRatio(CommonUtils.divideDataToString(dDestroyedTotalCount,  
  36.                     dAccessTotalCount, 2));  
  37.                 // 缓冲池丢失比率  
  38.                 objEjbVO.setCachePoolMissRatio(CommonUtils  
  39.                     .divideDataToString(dMissTotalCount, dAccessTotalCount, 2));  
  40.                 // 缓冲池超时比率  
  41.                 objEjbVO.setCachePoolTimeoutRatio(CommonUtils.divideDataToString(dTimeoutTotalCount,  
  42.                     dAccessTotalCount, 2));  
  43.                 // objRuntime = (ObjectName) jmxSession.getAttribute(objEntry, "CacheRuntime");  
  44.                 // // 缓存丢失比率 =(缓存丢失总数/缓存访问总数)* 100  
  45.                 // double dCacheMissCount = jmxSession.getDoubleAttribute(objRuntime, "CacheMissCount");  
  46.                 // double dActivationCount = jmxSession.getDoubleAttribute(objRuntime, "ActivationCount");  
  47.                 // objEjbVO.setCachedMissRatio(CommonUtils.divideDataToString(dCacheMissCount, dActivationCount,  
  48.                 // 2));  
  49.                 // objRuntime = (ObjectName) jmxSession.getAttribute(objEntry, "LockingRuntime");  
  50.                 // // 锁定等待程序比率  
  51.                 // // Lock Timeout Ratio =(Lock Manager Timeout Total Count / Lock Manager Total Access Count) * 100  
  52.                 // double dWaiterCurrentCount = jmxSession.getDoubleAttribute(objRuntime, "WaiterCurrentCount");  
  53.                 // double dLockCurrentCount = jmxSession.getDoubleAttribute(objRuntime, "LockEntriesCurrentCount");  
  54.                 // objEjbVO.setLockWaitRatio(CommonUtils.divideDataToString(dWaiterCurrentCount, dLockCurrentCount,  
  55.                 // 2));  
  56.                 // // Lock Timeout Ratio =(Lock Manager Timeout Total Count / Lock Manager Total Access Count) * 100  
  57.                 // // 锁定超时比率  
  58.                 // double dLockManagerAccessCount = jmxSession.getDoubleAttribute(objRuntime,  
  59.                 // "LockManagerAccessCount");  
  60.                 // dTimeoutTotalCount = jmxSession.getDoubleAttribute(objRuntime, "TimeoutTotalCount");  
  61.                 // objEjbVO.setLockTimeoutRatio(CommonUtils.divideDataToString(dTimeoutTotalCount,  
  62.                 // dLockManagerAccessCount, 2));  
  63.                 //                      
  64.                 objRuntime = (ObjectName) jmxSession.getAttribute(objEntry, "TransactionRuntime");  
  65.                 double dTranCommTotalCount =  
  66.                     jmxSession.getDoubleAttribute(objRuntime, "TransactionsCommittedTotalCount");  
  67.                 double dTranRollBackCount =  
  68.                     jmxSession.getDoubleAttribute(objRuntime, "TransactionsRolledBackTotalCount");  
  69.                 double dTranTimeOutTotalCount =  
  70.                     jmxSession.getDoubleAttribute(objRuntime, "TransactionsTimedOutTotalCount");  
  71.                 // 事务回滚比率  
  72.                 objEjbVO.setTransactionRollBackRatio(CommonUtils.divideDataToString(dTranRollBackCount,  
  73.                     dTranCommTotalCount, 2));  
  74.                 // 事务超时比率  
  75.                 objEjbVO.setTransactionTimeoutRatio(CommonUtils.divideDataToString(dTranTimeOutTotalCount,  
  76.                     dTranCommTotalCount, 2));  
  77.                 lstEjb.add(objEjbVO);  
  78.             }  
  79.         }  
  80.     }  
  81.     return lstEjb;  
  82. }  

转载于:https://my.oschina.net/u/2364025/blog/1785563

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值