📄 wsconfigmanagement.java
字号:
if (mlss == null || mlss.length == 0) {
return PmiConstants.LEVEL_DISABLE;
}
if (mlss[0] != null)
return mlss[0].getLevel();
} catch (Exception ex) {
// ex.printStackTrace();
}
return PmiConstants.LEVEL_DISABLE;
}
// Attribute : The average CPU utilization since the server was started
public String getCPUUsage() {
return new Long(getCPUUsage(perfName, serverName)).toString();
}
public long getCPUUsage(ObjectName perfMBean, ObjectName serverName) {
WSStats myStats = null;
long cpu = 0;
StatDescriptor mysd = new StatDescriptor(
new String[] { PmiConstants.SYSTEM_MODULE });
MBeanStatDescriptor mymsd = new MBeanStatDescriptor(serverName, mysd);
Object[] params = new Object[] { mymsd, new Boolean(false) };
String[] signature = new String[] {
"com.ibm.websphere.pmi.stat.MBeanStatDescriptor",
"java.lang.Boolean" };
try {
myStats = (WSStats) adminClient.invoke(perfMBean, "getStatsObject",
params, signature);
} catch (Exception e) {
e.printStackTrace();
}
AverageStatisticImpl cpuInfo = (AverageStatisticImpl) myStats
.getStatistic(WSSystemStats.CPUUsageSinceServerStarted);
cpu = cpuInfo.getCount();
return cpu;
}
/*
* Attribute : Returns the IP address of the given host Using JVM Bean
* directly
*/
public String getIpAddress() {
return getIpAddress(jvmName, hostName);
}
public String getIpAddress(ObjectName jvmName, String hostName) {
String ip = null;
Object[] params = new Object[] { new String(hostName) };
String[] signature = new String[] { "java.lang.String" };
try {
ip = (String) adminClient.invoke(jvmName, "getIPAddress", params,
signature);
} catch (Exception e) {
e.printStackTrace();
}
return ip;
}
/*
* Attribute : Returns Total number of concurrently active threads No MBean
* support,so I use MBeanStatDescriptor
*/
public String getThreadActiveNums() {
return new Long(getThreadActiveNums(perfName, serverName)).toString();
}
public long getThreadActiveNums(ObjectName perfMBean, ObjectName serverName) {
WSStats myStats = null;
long activeNums = 0;
StatDescriptor mysd = new StatDescriptor(
new String[] { PmiConstants.THREADPOOL_MODULE });
MBeanStatDescriptor mymsd = new MBeanStatDescriptor(serverName, mysd);
Object[] params = new Object[] { mymsd, new Boolean(false) };
String[] signature = new String[] {
"com.ibm.websphere.pmi.stat.MBeanStatDescriptor",
"java.lang.Boolean" };
try {
myStats = (WSStats) adminClient.invoke(perfMBean, "getStatsObject",
params, signature);
} catch (Exception e) {
e.printStackTrace();
}
BoundedRangeStatisticImpl thread = (BoundedRangeStatisticImpl) myStats
.getStatistic(WSThreadPoolStats.ActiveCount);
activeNums = thread.getCurrent();
return activeNums;
}
/*
* mainTable:jdbc conn pool
*/
// public String getJDBCConnNums(){
// return new Long(getJDBCConnNums(perfName,serverName)).toString();
// }
// public long getJDBCConnNums(ObjectName perfMBean, ObjectName serverName) {
// WSStats myStats = null;
// long jdbcNums = 0;
// StatDescriptor mysd = new StatDescriptor(
// new String[] { PmiConstants.CONNPOOL_MODULE });
// MBeanStatDescriptor mymsd = new MBeanStatDescriptor(serverName, mysd);
// Object[] params = new Object[] { mymsd, new Boolean(false) };
// String[] signature = new String[] {
// "com.ibm.websphere.pmi.stat.MBeanStatDescriptor",
// "java.lang.Boolean" };
// try {
// myStats = (WSStats) adminClient.invoke(perfMBean, "getStatsObject",
// params, signature);
//
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// BoundedRangeStatisticImpl jdbc = (BoundedRangeStatisticImpl) myStats
// .getStatistic(WSJDBCConnectionPoolStats.PoolSize);
// jdbcNums = jdbc.getCurrent();
// return jdbcNums;
// }
/*
* Attribute : Returns Total number of threads that are destroyed No MBean
* support,so I use MBeanStatDescriptor
*/
public String getThreadDestroyNums() {
return new Long(getThreadDestroyNums(perfName, serverName)).toString();
}
public long getThreadDestroyNums(ObjectName perfMBean, ObjectName serverName) {
WSStats myStats = null;
long destroyNums = 0;
StatDescriptor mysd = new StatDescriptor(
new String[] { PmiConstants.THREADPOOL_MODULE });
MBeanStatDescriptor mymsd = new MBeanStatDescriptor(serverName, mysd);
Object[] params = new Object[] { mymsd, new Boolean(false) };
String[] signature = new String[] {
"com.ibm.websphere.pmi.stat.MBeanStatDescriptor",
"java.lang.Boolean" };
try {
myStats = (WSStats) adminClient.invoke(perfMBean, "getStatsObject",
params, signature);
} catch (Exception e) {
e.printStackTrace();
}
CountStatisticImpl thread = (CountStatisticImpl) myStats
.getStatistic(WSThreadPoolStats.DestroyCount);
destroyNums = thread.getCount();
return destroyNums;
}
/*
* Attribute : Returns the amount of time (ms) the JVM is running
*/
public String getJVMRunTime() {
return new Long(getJVMRunTime(perfName, jvmName)).toString();
}
public long getJVMRunTime(ObjectName perfName, ObjectName jvmOn) {
long runTime = 0;
WSStats jvmStats = getStatsFromIndividualMBean(perfName, jvmOn);
CountStatisticImpl jvmHeapStatistic = (CountStatisticImpl) jvmStats
.getStatistic(WSJVMStats.UpTime);
runTime = jvmHeapStatistic.getCount();
return runTime;
}
/*
* Attribute : Returns the number of connection timeouts in the pool
*/
public String getFaultJDBCConnNums() {
return new Long(getFaultJDBCConnNums(perfName, jdbcName)).toString();
}
public long getFaultJDBCConnNums(ObjectName perfName, ObjectName jdbcName) {
long jdbcConnFaultNums = 0;
WSStats jdbcStats = getStatsFromIndividualMBean(perfName, jdbcName);
CountStatisticImpl jdbcConnStats = (CountStatisticImpl) jdbcStats
.getStatistic(WSJDBCConnectionPoolStats.FaultCount);
if (jdbcConnStats != null) {
jdbcConnFaultNums = jdbcConnStats.getCount();
}
return jdbcConnFaultNums;
}
/*
* Attribute : Returns amount of time in milliseconds spent executing in the
* JDBC driver
*/
public String getJDBCConnTime() {
return new Long(getJDBCConnTime(perfName, jdbcName)).toString();
}
public long getJDBCConnTime(ObjectName perfName, ObjectName jdbcName) {
long jdbcConnTime = 0;
WSStats jdbcStats = getStatsFromIndividualMBean(perfName, jdbcName);
TimeStatisticImpl jdbcConnStats = (TimeStatisticImpl) jdbcStats
.getStatistic(WSJDBCConnectionPoolStats.JDBCTime);
if (jdbcConnStats != null) {
jdbcConnTime = jdbcConnStats.getMaxTime();
}
return jdbcConnTime;
}
/*
* Attribute : Returns the number of new objects created by the object pool
*/
public String getNewObjectByPool() {
return new Long(getNewObjectByPool(perfName, objectPoolName))
.toString();
}
public long getNewObjectByPool(ObjectName perfName,
ObjectName objectPoolName) {
long newObject = 0;
WSStats objcetStats = getStatsFromIndividualMBean(perfName,
objectPoolName);
CountStatisticImpl newObjectStats = (CountStatisticImpl) objcetStats
.getStatistic(WSObjectPoolStats.ObjectsCreatedCount);
if (newObjectStats != null) {
newObject = newObjectStats.getCount();
}
return newObject;
}
public MBeanStatDescriptor[] listMBeanStatDescriptor(ObjectName perfOName,
ObjectName mName) {
if (mName == null)
return null;
try {
Object[] params = new Object[] { mName };
String[] signature = new String[] { "javax.management.ObjectName" };
MBeanStatDescriptor[] msds = (MBeanStatDescriptor[]) adminClient
.invoke(perfOName, "listStatMembers", params, signature);
return msds;
} catch (Exception e) {
new AdminException(e).printStackTrace();
System.out.println("listStatMembers: Exception Thrown");
return null;
}
}
public static void main(String[] args) {
WSConfigManagement ws = new WSConfigManagement();
//System.out.println(ws.getJDBCConnNums());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -