websphere监测servlet没有想要的结果

藍色的海 发布于 2012/07/26 10:00
阅读 390
收藏 1

websphere项目中要监测servlet,要求如下:监控某个Servlet可用性,总请求数,Servlet的响应时间,错误总数。

于是写了一个servlet测试文件:TestServlet,并打包为war文件:testServlet.war。然后把它安装到websphere中。

写了如下代码对此servlet文件进行监测:

 

try{
	    		ObjectName  obj=new ObjectName("WebSphere:WebModule=testServlet.war,name=TestServlet,process=server1,Application=testServlet_war,platform=dynamicproxy,J2EEApplication=testServlet_war,node=PC--20120719ZOWNode02,J2EEName=testServlet_war#testServlet.war#TestServlet,j2eeType=Servlet,J2EEServer=server1,Server=server1,version=6.1.0.0,type=Servlet,mbeanIdentifier=testServlet_war#testServlet.war#TestServlet,cell=PC--20120719ZOWNode02Cell,spec=1.0");
ObjectName perfOn=getPerf_1();
	    		Object[] params = new Object[]{obj,new Boolean(true)};  
	        	String[] signature= new String[]{"javax.management.ObjectName",
	        	   "java.lang.Boolean"}; 
	        	StatsImpl myStats =(StatsImpl)adminClient.invoke(perfOn,"getStatsObject",params,signature);
System.out.println(myStats.toString());
}catch(Exception e){
	    		e.printStackTrace();
	    	}

运行后,输出如下结果:

 

2012-7-26 9:53:42 com.ibm.ws.pmi.server.ModuleConfigParser
严重: PMI0010W
2012-7-26 9:53:42 com.ibm.ws.pmi.server.ModuleConfigParser
严重: PMI0010W

Stats name=TestServlet, type=com.ibm.ws.wswebcontainer.stats.servletStats
{
name=null, ID=11, description=null, unit=null, type=CountStatistic, count=1

name=null, ID=12, description=null, unit=null, type=RangeStatistic, lowWaterMark=0, highWaterMark=1, current=0, integral=15.0

name=null, ID=13, description=null, unit=null, type=AverageStatistic, avg=15.0, min=15, max=15, total=15, count=1, sumSq=225.0, type=TimeStatistic, avg=15.0, min=15, max=15, total=15, count=1, sumSq=225.0

name=null, ID=14, description=null, unit=null, type=CountStatistic, count=0

Stats name=webAppModule.servlets.urls, type=com.ibm.ws.wswebcontainer.stats.urlStats
{
name=null, ID=15, description=null, unit=null, type=CountStatistic, count=1

name=null, ID=16, description=null, unit=null, type=RangeStatistic, lowWaterMark=0, highWaterMark=1, current=0, integral=15.0

name=null, ID=17, description=null, unit=null, type=AverageStatistic, avg=15.0, min=15, max=15, total=15, count=1, sumSq=225.0, type=TimeStatistic, avg=15.0, min=15, max=15, total=15, count=1, sumSq=225.0

Stats name=/servlet/TestServlet, type=com.ibm.ws.wswebcontainer.stats.urlStats
{
name=null, ID=15, description=null, unit=null, type=CountStatistic, count=1

name=null, ID=16, description=null, unit=null, type=RangeStatistic, lowWaterMark=0, highWaterMark=1, current=0, integral=15.0

name=null, ID=17, description=null, unit=null, type=AverageStatistic, avg=15.0, min=15, max=15, total=15, count=1, sumSq=225.0, type=TimeStatistic, avg=15.0, min=15, max=15, total=15, count=1, sumSq=225.0
}}}

之前用相同的方法对JVM进行监测,代码如下:

 

try{
	    		ObjectName  obj=new ObjectName("WebSphere:name=JVM,process=server1,platform=proxy,node=PC--20120719ZOWNode02,j2eeType=JVM,J2EEServer=server1,version=6.1.0.0,type=JVM,mbeanIdentifier=JVM,cell=PC--20120719ZOWNode02Cell,spec=1.0");
ObjectName perfOn=getPerf_1();
	    		Object[] params = new Object[]{obj,new Boolean(true)};  
	        	String[] signature= new String[]{"javax.management.ObjectName",
	        	   "java.lang.Boolean"}; 
	        	StatsImpl myStats =(StatsImpl)adminClient.invoke(perfOn,"getStatsObject",params,signature);
System.out.println(myStats.toString());
}catch(Exception e){
	    		e.printStackTrace();
	    	}

便能得到如下结果:

 

Stats name=jvmRuntimeModule, type=jvmRuntimeModule#
{
name=HeapSize, ID=1, description=Java 虚拟机运行时中的总内存(以千字节计)。, unit=千字节, type=BoundedRangeStatistic, lowWaterMark=51200, highWaterMark=107119, current=107119, integral=0.0, lowerBound=51200, upperBound=262144

name=FreeMemory, ID=2, description=Java 虚拟机运行时中的空闲内存(以千字节计)。, unit=千字节, type=CountStatistic, count=358

name=UsedMemory, ID=3, description=Java 虚拟机运行时中使用的内存容量(以千字节计)。, unit=千字节, type=CountStatistic, count=106760

name=UpTime, ID=4, description=Java 虚拟机已经运行的时间数(以秒为单位)。, unit=SECOND, type=CountStatistic, count=1297

name=ProcessCpuUsage, ID=5, description=Java 虚拟机的 CPU 使用情况(以百分比为单位)。, unit=不适用, type=CountStatistic, count=2
}

想不明白要怎样才能监测出servlet的数据??

加载中
返回顶部
顶部