`
征途2010
  • 浏览: 247596 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

通过JMX监控weblogic服务

阅读更多

一、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

 

分享到:
评论
5 楼 minser 2015-12-05  
博主  您好! 能否把这个工程的 发给我ttnsdcn@qq.com. 有偿的亦可
4 楼 征途2010 2015-10-20  
ybbtgvusr 写道
你好,有完整代码吗?麻烦分享一下,多谢。email:172971050@QQ.COM

你需要哪部分代码?
3 楼 ybbtgvusr 2015-10-14  
你好,有完整代码吗?麻烦分享一下,多谢。email:172971050@QQ.COM
2 楼 征途2010 2015-06-23  
    /**
     * 获取进程ID
     * 
     * @return strPID
     */
    public String getMiddlewarePID() {
        String strPID = "";
        try {
            RuntimeMXBean objRun =
                (RuntimeMXBean) ManagementFactory.newPlatformMXBeanProxy(jmxSession.getConnection(),
                    ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean.class);
            // 获取进程ID
            strPID = objRun.getName().split("@")[0];
        } catch (Exception e) {
            LOGGER.error("请检查jmx远程端口是否配置" + e.getMessage());
        }
        return strPID;
    }

看看这个是否是你需要的
1 楼 dave20 2015-06-09  
您好!请问获取进程ID,这个方法getMiddlewarePID()是怎样的呢?文章上没写这个方法。目前急需知道怎么通过jmx获取weblogic的实例进程是否挂起,或知道获取Weblogic进程的相关Mbean。如果知道希望能回复。谢谢

相关推荐

    jmx监控weblogic,tomcat,websphere源码

    在本项目中,"jmx监控weblogic,tomcat,websphere源码"涉及了使用JMX来监控三个主流的Java应用服务器:WebLogic、Tomcat和WebSphere。这些服务器都是企业级应用部署的常见选择,对它们的监控对于确保系统性能、稳定性...

    通过jmx监控管理weblogic

    BEA WebLogic Server实现了JMX大部分的API,并且提供了一个完全兼容JMX的控制台来管理各种资源。OPEN SOURCE的应用服务器JBoss也是基于JMX来实现。并且对之评价很高,认为是目前为止最好的软件集成工具。JBoss的成功...

    Java 版jmx 监控中间件weblogic

    Java版 jmx 监控weblogic 生成html

    LR上配置监控WEBLOGIC

    接下来,我们将详细介绍如何在LR中配置JMX监控WebLogic的具体步骤。 1. **修改WebLogicMon.ini文件**: - 打开LR安装目录下的`dat\monitors`文件夹中的`WebLogicMon.ini`文件。 - 修改JVM路径:将默认的`JVM=...

    java jvisualvm 监控weblogic配置方法

    ### Java VisualVM 监控 WebLogic 配置详解 ...通过上述步骤,可以有效地使用 Java VisualVM 来监控 WebLogic 服务器及其管理下的多个实例,从而帮助开发者和系统管理员更好地了解应用程序的运行状态和性能表现。

    loadrunner 监视 weblogic(JMX) 操作详细步骤.txt

    LoadRunner作为一款强大的性能测试工具,支持多种类型的监控方式,其中通过Java Management Extensions (JMX)来监控WebLogic服务器是一种非常实用的方法。本文将详细介绍如何配置LoadRunner以便于监视WebLogic服务器...

    Jprofile资源监控WebLogic部署项目占用资源的大小步骤---操作步骤,图片

    以下是使用JProfiler监控WebLogic部署项目资源占用的详细步骤: 1、**下载与安装JProfiler**:首先,你需要从官方网站获取JProfiler的最新版本并完成安装。确保你的Java环境已经配置好,因为JProfiler依赖于Java...

    weblogic监控 weblogic调优 weblogic版本区别 weblogic启动关闭脚本

    此外,还可以利用JMX(Java Management Extensions)和WLDF(WebLogic Diagnostic Framework)进行更深入的监控和诊断,以便及时发现并解决性能问题。 二、WebLogic调优 WebLogic调优主要包括JVM参数调整、内存设置...

    weblogic监控脚本

    这篇博客文章“Weblogic监控脚本”可能涉及了如何利用脚本来自动化监控WebLogic服务器的关键指标,如内存使用、CPU利用率、JVM性能等。 在WebLogic中,监控可以通过多种方式实现,包括使用内置的管理控制台、WLST...

    weblogic 服务器管理(中文版)

    【监控WebLogic域】 监控是确保系统性能和稳定性的关键。WebLogic Server提供了丰富的监控工具,包括控制台、JMX MBeans和日志分析,可以实时查看服务器性能指标,如CPU使用率、内存占用、请求处理速度等,以便及时...

    WeblogicJMX:Weblogic JMX 实用程序

    网络逻辑JMX这是一个正在进行的工作,将经常更新,直到完成一组用于 9.X 及更高版本的 Weblogic 服务器的 JMX 服务器实用程序。 目前实时给出一些监控统计,后续会更新更多功能特征目前可以使用以下功能: JVM 监控...

    Linux下 通过jconsole远程监控weblogic

    以下是如何在CentOS 7.5上配置和使用JConsole来远程监控WebLogic 12c的详细步骤: 1. **环境准备**: - 操作系统:CentOS 7.5 - 应用服务器:WebLogic 12c - JDK版本:1.8 2. **配置WebLogic**: 首先,我们...

    WebLogic服务器管理概述

    WebLogic服务器管理是Oracle公司提供的一个企业级Java应用服务器,用于部署、管理和监控Java应用程序和服务。WebLogic服务器作为Java EE(现在称为Jakarta EE)平台的一部分,为开发和运行分布式多层应用程序提供了...

    Eclipse下Weblogic配置详解

    - WebLogic插件还提供了应用日志查看、JMX监控等功能。 了解并掌握这些步骤和Eclipse与WebLogic的集成特性,将有助于你高效地进行Java EE项目的开发和调试。同时,提供的文档如`weblogic.doc`和`EclipseWebLogic...

    weblogic weblogic weblogic

    9. **监控与诊断**:通过JMX(Java Management Extensions)和管理控制台,可以实时监控服务器状态,收集性能数据,并进行问题诊断。 10. **持续集成与自动化**:WebLogic支持Maven、Gradle等构建工具,便于集成到...

    Weblogic 服务器管理

    5. **JMX(Java Management Extensions)**:JMX是Java平台的管理系统架构,WebLogic使用JMX来管理和监控服务器状态,开发者可以通过编写MBeans(Managed Beans)来扩展管理功能。 6. **安全性**:WebLogic提供了...

    WebLogic学习指南

    - **JMX(Java Management Extensions)**:利用JMX监控WebLogic服务器状态和性能。 9. **故障排查** - **错误分析**:识别并解决常见的WebLogic错误和问题。 - **性能问题诊断**:诊断和修复性能瓶颈。 10. **...

    weblogic的MX程序设计

    ### WebLogic的MX程序设计详解 ...此外,还详细讲解了如何使用JMX监控WebLogic Server的关键指标,为运维人员提供了强大的工具支持。希望本文能帮助读者更好地理解和运用JMX来提高WebLogic Server的管理水平。

    tomcat_weblogic_jmx.txt

    它允许开发者监控和管理资源(如应用程序、设备和服务),通过标准接口暴露资源的属性、操作和事件。JMX 提供了一个灵活且可扩展的方式来管理基于 Java 的应用。 #### 二、Tomcat JMX 开通步骤 **1. 修改环境变量*...

Global site tag (gtag.js) - Google Analytics