性能测试中,我们经常希望一个平台能拦截、profile、分析性能数据,现实在一点点逼近.Jwebap:
效果图http://www.jwebap.org/detect/console/?null
官方文档:http://www.jwebap.org/index_zh.htm
作者blog:http://leadyu.javaeye.com/
Jwebap是无代码侵入、需要修改web.xml配置文件的java应用监控工具,轻易获取jdbc调用/http调用、方法调用耗时及是否有jdbc泄露。核心原理:应用asm字节码操作框架实现动态monitor。
另外一个工具:http://jamonapi.sourceforge.net/。
http://sourceforge.net/projects/jwebap/files/
解压后的jwebap_0.6.1.jar, tracer_0.6.1.jar及jwebap_0.6.1_all\lib目录下jar复制到jboss-4.2.2.GA\server\default\lib目录下。
修改tracer_0.6.1.jar/META-INF/plugin.xml文件,红色为修改项:
<?xml version="1.0" encoding="UTF-8"?>
<plugin>
<!--component-->
<component name="HttpComponent" type="org.jwebap.plugin.tracer.http.HttpComponent">
<component-param>
<name>trace-filter-active-time</name>
<value>-1</value>
<description>(ms) timings filter's over time</description>
</component-param>
<component-param>
<name>trace-max-size</name>
<value>1000</value>
<description>max over-time trace size</description>
</component-param>
</component>
<component name="MethodComponent" type="org.jwebap.plugin.tracer.method.MethodComponent">
<component-param>
<name>trace-filter-active-time</name>
<value>-1</value>
<description>(ms) timings filter's over time</description>
</component-param>
<component-param>
<name>trace-max-size</name>
<value>1000</value>
<description>max over-time trace size</description>
</component-param>
<component-param style="longtext">
<name>detect-clazzs</name>
<value>
com.ali.*;
</value>
<description>
package name and class name that monitored by MethodComponent,
e.g.: 'test.*;test.Test' , divided by ';'
</description>
</component-param>
</component>
<component name="JdbcComponent" type="org.jwebap.plugin.tracer.jdbc.JdbcComponent">
<component-param>
<name>trace-filter-active-time</name>
<value>-1</value>
<description>(ms) timings filter's over time</description>
</component-param>
<component-param>
<name>trace-max-size</name>
<value>1000</value>
<description>max over-time trace size</description>
</component-param>
<component-param style="longtext">
<name>connection-listener</name>
<value>
org.jwebap.plugin.tracer.http.ServletOpenedConnectionListener;org.jwebap.plugin.tracer.method.MethodOpenedConnectionListener
</value>
<description>Connection Listener</description>
</component-param>
<component-param style="longtext">
<name>driver-clazzs</name>
<value>org.apache.commons.dbcp.BasicDataSource</value>
<!--
<value>com.mysql.jdbc.Driver</value>
-->
<description>
</description>
</component-param>
</component>
…
</plugin>
修改好后重新替换入jar。如下是监控spring.war应用的操作过程。
修改jwebap.xml放到jboss-4.2.2.GA\server\default\deploy\spring.war\WEB-INF
<?xml version="1.0" encoding="UTF-8"?>
<jwebap>
<!--plugins-->
<plugin name="Tracer" ref="${ABSOLUTE_PATH}/tracer_0.6.1.jar"/>
…
</jwebap>
(${ABSOLUTE_PATH}是内置的变量,不必修改)
参考jwebap_0.6.1_all\bin\web-example.xml修改jboss-4.2.2.GA\server\default\deploy\spring.war\WEB-INF\web.xml:
<!-- begin jwebap-->
<context-param>
<param-name>jwebap-config</param-name>
<param-value>/WEB-INF/jwebap.xml</param-value>
</context-param>
<listener>
<listener-class>org.jwebap.startup.JwebapListener</listener-class>
</listener>
<filter>
<filter-name>PageDetectFilter</filter-name>
<filter-class>org.jwebap.plugin.tracer.http.DetectFilter</filter-class>
<init-param>
<param-name>excludeUrls</param-name>
<param-value>/detect;/detect/*;*.js;*.jpg;*.htm;*.html;*.gif;*.png;*.css;*.swf</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PageDetectFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>detect</servlet-name>
<servlet-class>org.jwebap.ui.controler.JwebapServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>detect</servlet-name>
<url-pattern>/detect/*</url-pattern>
</servlet-mapping>
<!-- end jwebap-->
有一点特别注意的是,在被监控的程序如spring.war目录jboss-4.2.2.GA\server\default\deploy\spring.war\WEB-INF\lib加入数据库驱动程序如commons-dbcp.jar,否则无法获取jdbc trace数据。
启动jboss,
执行应用操作,ie输入
http://localhost:8080/spring/detect/console/?null可以看到jwebap监控效果
jdbc traces:
http监控
Method监控
更多讨论可以在javaeye论坛搜索jwebap。
对于普通的web程序,jwebap支持不错。可以考虑内部系统开发性能优化时应用。
Webx工程只能监控jdbc调用,对于方法和http请求无法拦截.