JAMon监控web工程方法的调用性能
2014-06-13 18:16
387 查看
JAMon简介
JAMon的全名是:Java Application Monitor。它是一个小巧的,免费的,高性能的,线程安全的性能监测工具。
它可以用来测定系统的性能瓶颈,也可以用来监视用户和应用程序之间的交互情况。
Jamon主要是用来检测jee的应用程序。
JAMon集成到项目中
假设现在有一个项目名为bookShop,目录结构如下:
bookshop
java resources
src
com.allen.bookshop
filter
PageMonFilter
webContent
jamon
WEB-INF
web.xml
1.到官网去下载两个包:jamon.rar和jamon-sample.rar
http://sourceforge.net/projects/jamonapi/files/
jamon.rar里面有源码和api。
jamon-sample.rar里面有基本示例。
解压jamon-sample.rar,把解压后的文件jamon直接拷贝到webContent下,具体文件如下图:
2.把解压jamon-sample.rar后jamon文件里的webContent下的lib下的jar包,拷贝到自己工程的lib下。
3.新建一个PageMonFilter类,如上目录结构:
4.在web.xml上增加如下代码:
5.增加jamon_bean.xml文件, 用于配置你要监听哪些类。action方法不用配置,默认会监听。
6.在log4j.properties中添加如下配置:
重新启动工程。
至此,配置完成,现在可以访问http://localhost:8080/bookshop/jamon/menu.jsp访问jamon了
JAMon的全名是:Java Application Monitor。它是一个小巧的,免费的,高性能的,线程安全的性能监测工具。
它可以用来测定系统的性能瓶颈,也可以用来监视用户和应用程序之间的交互情况。
Jamon主要是用来检测jee的应用程序。
JAMon集成到项目中
假设现在有一个项目名为bookShop,目录结构如下:
bookshop
java resources
src
com.allen.bookshop
filter
PageMonFilter
webContent
jamon
WEB-INF
web.xml
1.到官网去下载两个包:jamon.rar和jamon-sample.rar
http://sourceforge.net/projects/jamonapi/files/
jamon.rar里面有源码和api。
jamon-sample.rar里面有基本示例。
解压jamon-sample.rar,把解压后的文件jamon直接拷贝到webContent下,具体文件如下图:
2.把解压jamon-sample.rar后jamon文件里的webContent下的lib下的jar包,拷贝到自己工程的lib下。
3.新建一个PageMonFilter类,如上目录结构:
import java.io.IOException; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import com.jamonapi.JAMonFilter; import com.jamonapi.MonKeyImp; import com.jamonapi.Monitor; import com.jamonapi.MonitorFactory; public class PageMonFilter extends JAMonFilter { private static final long serialVersionUID = 5746197114960908454L; private FilterConfig filterConfig = null; public void init( FilterConfig filterConfig ) throws ServletException { this.filterConfig = filterConfig; } public void destroy() { this.filterConfig = null; } public void doFilter( ServletRequest request, ServletResponse response, FilterChain filterChain ) throws IOException, ServletException { Monitor allPages = MonitorFactory.start( new MonKeyImp( "jammon.webui.allPages", getURI( request ), "ms." ) ); Monitor monitor = MonitorFactory.start( getURI( request ) ); try { filterChain.doFilter( request, response ); } finally { monitor.stop(); allPages.stop(); } } protected String getURI( ServletRequest request ) { if ( request instanceof HttpServletRequest ) { return ((HttpServletRequest)request).getRequestURI(); } else { return "Not an HttpServletRequest"; } } }
4.在web.xml上增加如下代码:
<filter> <filter-name>JAMonFilter</filter-name> <filter-class>com.allen.bookshop.filter.PageMonFilter</filter-class> </filter> <filter-mapping> <filter-name>JAMonFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
5.增加jamon_bean.xml文件, 用于配置你要监听哪些类。action方法不用配置,默认会监听。
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:osgi="http://www.springframework.org/schema/osgi" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd "> <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="beanNames"> <list> <value>bookshopService</value> </list> </property> <property name="interceptorNames"> <list> <value>jamonInterceptor</value> </list> </property> </bean> <bean id="jamonInterceptor" class="org.springframework.aop.interceptor.JamonPerformanceMonitorInterceptor"> </bean> </beans>
6.在log4j.properties中添加如下配置:
log4j.logger.org.springframework.aop.interceptor.JamonPerformanceMonitorInterceptor = TRACE
重新启动工程。
至此,配置完成,现在可以访问http://localhost:8080/bookshop/jamon/menu.jsp访问jamon了
相关文章推荐
- C#.net中web工程中创建用户控件和被调用的方法
- C#.net中web工程中创建用户控件和被调用的方法
- HttpClient调用Web工程的Spring @Controller方法
- 非.NET语言调用.NET XML Web Services返回的数据集合的两个方法
- 在WEB页面中调用NetMeeting 方法
- 非.NET语言调用.NET XML Web Services返回的数据集合的两个方法
- 非.NET语言调用.NET XMLWeb Services返回的数据集合的两个方法
- 有关AJAX异步调用web服务中带参数的方法的心得
- 从 ASPX 页面进行 Web 服务调用时的性能考虑
- 如何用C#创建一个类并在其他Web页中调用该类的方法(1)
- WEB上调用HttpWebRequest奇怪问题的解决方法
- Ajax 1.0 中使用web控件调用后台方法的用法.
- Web 性能测试需求分析方法-1
- 从 ASPX 页面进行 Web 服务调用时的性能考虑
- 调用.NET XML Web Services返回的数据集合的方法
- C#实现Web程序调用Windows程序的方法
- 从 ASPX 页面进行 Web 服务调用时的性能考虑
- 动态调用对象的属性和方法——性能和灵活性兼备的方法
- 从 ASPX 页面进行 Web 服务调用时的性能考虑
- post方法调用web服务(改进)