About JAMon
The full name of JAMon is Java Application Monitor. It is a small, free, high-performance, thread-safe performance monitoring tool.
It can be used to determine the performance bottleneck of the system, or to monitor the interaction between users and applications.
Jamon is mainly used to detect jee applications.
JAMon is integrated into the project.
Suppose there is a project named bookShop. The directory structure is as follows:
Bookshop
Java resources
Src
Com. allen. bookshop
Filter
PageMonFilter
WebContent
Jamon
WEB-INF
Web. xml
1. Download two packages from the official website: jamon.rarand jamon-sample.rar.
Http://sourceforge.net/projects/jamonapi/files/
Jamon.rar contains the source code and api.
There are basic examples in the jamon-sample.rar.
Decompress jamon-sample.rar and copy the decompressed file jamon to webContent. The specific file is as follows:
2. decompress the jar package under lib in the webContent file of jamon-sample.rar and copy it to the lib of your project.
3. Create a PageMonFilter class, as shown in the preceding directory structure:
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. Add the following code to 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. Add the jamon_bean.xml file to configure the classes you want to listen. The action method does not need to be configured. It listens by default.
<?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. Add the following configuration in log4j. properties:
log4j.logger.org.springframework.aop.interceptor.JamonPerformanceMonitorInterceptor = TRACE
Restart the project.
Now, the configuration is complete. Now you can access http: // localhost: 8080/bookshop/jamon/menu. jsp to access jamon.