通过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
通过JMX监控weblogic服务的更多相关文章
- 通过Nagios监控weblogic服务
1.前言 前段时间搭建了一套Nagios监控服务,心血来潮想自己写一个脚本,拓展Nagios插件来监控公司的weblogic服务. 环境:weblogic10.3.3.0 . CentOS6 ...
- 通过JMX获取weblogic的监控指标
通过JMX获取weblogic的监控数据,包括JDBC,SESSION,SERVERLET,JVM等信息.主要用到weblogic自己的t3协议,所以要用到weblogic的jar包:wlfullcl ...
- zabbix监控tomcat(使用jmx监控,但不使用系统自带模版)
一,zabbx使用jmx监控tomcat的原理分析 1.Zabbix-Server找Zabbix-Java-Gateway获取Java数据 2.Zabbix-Java-Gateway找Java程序(j ...
- Linux记录-JMX监控JAVA进程
3.修改xxx.sh 加入export JAVA_OPTS="-Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.mana ...
- Linux记录-JMX监控Tomcat上传到falcon
1.登录测试服务器xxxxxx xxxxxx su root输入xxxx 2.先修改Tomcat的启动脚本,(linux下为catalina.sh),添加以下内容: CATALINA_OPTS=&qu ...
- 服务器开启JMX监控
JMX是一个框架,提供了一种功能,可以实时查询应用程序中通过JMX向外部公布的相应参数或者是其他应用程序,同时也可以通过JMX来实时地调用应用程序使用JMX向外部公布的接口,来完成一些功能操作. 如果 ...
- Zabbix 通过 JMX 监控 java 进程
参考: [ JMX monitoring ] [ Zabbix Java gateway ] [ JMX Monitoring (Java Gateway) not Working ] [ Monit ...
- 监控应用服务器使用JMX监控Tomcat (推荐)
前言:做了一个监控应用服务器的项目(支持Tocmat.WebSphere.WebLogic各版本), 过程也算是磕磕绊绊,由于网上缺少相关资料,或者深陷于知识的海洋难以寻觅到有效的资料,因而走过不少弯 ...
- 使用Collectd + InfluxDB + Grafana进行JMX监控
我们已经看到使用Collectd监控CPU /内存利用率(本文).但它没有提供所有信息来确定性能问题的瓶颈.在本文中,我们将使用Collectd Java插件来使用其JMX技术来监视和管理Java虚拟 ...
- Jconsole/jvisualvm远程监控weblogic中间件配置
1.进入linu操作界面,进入到启动服务目录下 2.选择要监控的服务的启动项,进入到编辑状态(注意:要先将该文件进行备份),如下图所示 3.修改USER_AGRS域,添加如下内容,注意修改IP USE ...
随机推荐
- Jenkins构建UI自动化项目,指定本地执行,没弹起浏览显示
1. 原因分析 为什么执行web没有弹出浏览器,Jenkins日志显示正在执行中 jenkins是用windows installer 安装成 windows的服务了,那么启动windows后jenk ...
- RIP总结
RIP 两种更新方式:定期更新和触发更新 管理距离为120,更新使用UDP520,更新周期30s,使用跳数作为度量值,最大15 RIP有三个版本RIPv1,RIPv2,RIPn ...
- 日常Bug排查-改表时读数据不一致
前言 日常Bug排查系列都是一些简单Bug的排查.笔者将在这里介绍一些排查Bug的简单技巧,同时顺便积累素材. Bug现场 线上连续两天出现NP异常,而且都是凌晨低峰期才出现,在凌晨的流量远没有白天高 ...
- FEDORA34 安装CUDA11.3
FEDORA34 安装CUDA11.3 首先确保能装上最新的显卡驱动. FEDORA显卡驱动安装 然后去官网下fedora对应的.run安装文件.运行安装, 但不要选装驱动. 完成后加环境变量: # ...
- paraview安装
apt 安装 sudo apt install paraview 安装包安装 参考 https://blog.csdn.net/weixin_47492286/article/details/1272 ...
- [UG 二次开发 python ] 截图,并用 opencv 显示出来
需要 numpy,cv2 截图,去除背景,只显示主要部分 # nx: threaded from typing import Dict import NXOpen import numpy as np ...
- 基于SSD202D芯片的最小嵌入式Linux开发板来了 仅需99元 入门嵌入式Linux必选
- SpringBoot可视化接口开发工具magic-api
magic-api简介 magic-api是一个基于Java的接口快速开发框架,编写接口将通过magic-api提供的UI界面完成,自动映射为HTTP接口,无需定义Controller.Service ...
- JavaWeb踩坑记录
org.apache.ibatis.binding.BindingException: Parameter 'XXXX' not found. 或 There is no getter for pro ...
- Spring Boot XML文件头
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-/ ...