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了

    

JAMon监控web工程方法的调用性能的更多相关文章

  1. 监控web服务方法

    本地监控:端口  netstat -anltup | grep 80  nmap ip -p 80 telnet ip:80 lsof -i :80|wc -l 进程 ps -ef| grep ngi ...

  2. JAMon监控SQL执行时间

    JAMon监控web工程方法的调用性能 http://www.cnblogs.com/zfc2201/p/3786365.html 这往往篇文章主要告诉大家如何监控web方法调用时间,在这个基础这上, ...

  3. 在javaEE下学习web(在eclipse中开发动态的WEB工程,servlet的环境搭建,及servlet的一些方法)

    一个简便的方法实现javaee版的eclipse开发动态的WEB工程(javaWEB项目)1.把开发选项切换到javaEE2. 可以在window->shou view 中找到package e ...

  4. zabbix如何监控WEB应用性能

    HTTP服务目前最流行的互联网应用之一,如何监控服务的健康状态对系统运维来说至关重要.   Zabbix本身提供了对WEB应用程序的监控,比如监控WEB程序的Download Speed,Respon ...

  5. 根据wsdl文件,Web工程自动生成webservice客户端调用

    根据wsdl文件,Web工程自动生成webservice客户端调用 1,工具:带有webservice插件的eclips 2,步骤: (1),新建一个Web工程:WSDLTest (2),浏览器访问W ...

  6. zabbix 监控web网站性能

    一直在纠结用什么实例来给大家演示呢?想来想去还是官方的好,那我们怎么用zabbix监控web性能和可用性呢?我们这边分为几个步骤:打开网站.登陆.登陆验证.退出,一共4个小step,看实例. 检测流程 ...

  7. Eclipse动态web工程(Dynamic Web Project)添加jar文件的正确方法

    Eclipse中,创建了动态web工程之后,如果需要添加新的jar文件,有两种方法.第一种是配置工程的“build path”,第二种则是将jar文件放在工程目录下的“/WebContent/WEB- ...

  8. 使用AdvancedInstaller打包web工程设置tomcat端口的方法

    原文:使用AdvancedInstaller打包web工程设置tomcat端口的方法 1.首先,要把你要打包的tomcat下的server.xml文件删掉,因为tomcat自带的serv ...

  9. 自学Zabbix4.1 zabbix监控web服务器访问性能

    自学Zabbix4.1 zabbix监控web服务器访问性能 使用Zabbix实现对web性能的监控,通过它可以了解web站点的可用性以及性能.最终将各项指标绘制到图形中,这样我们可以了解到一个站点的 ...

随机推荐

  1. SAR图像处理 MSTAR数据库利用问题

    本人最近刚接手的新活,打算从事SAR目标识别的研究,从美国的mstar数据库中下到一些资源,但是这些数据并不是原始图片的格式,需要转换,由于刚刚接触,并不太了解,所以特此请教!如有感兴趣的朋友可以一起 ...

  2. LeetCode189:Rotate Array

    Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array ...

  3. 【转】针对Android上的ROP攻击剖析

    引言       ROP(Return-oriented programming),即“返回导向编程技术”.其核心思想是在整个进程空间内现存的函数中寻找适合指令片断(gadget),并通过精心设计返回 ...

  4. junit单元测试+junit与Spring结合

    配置:右键要加入单元测试的工程,选择properties,然后选择java build path,选择add library,选择junit即可. 编写:右键要测试的class,new一个junit ...

  5. java字节流和字符流编码格式(转自姚刚)

    /** * 字节流和字符流的区别, * (1)字符流带有缓冲,必须flush或close后数据才会从缓存中写入磁盘文件. * 字节流直接写文件. * (2)字符流在创建流的时候,指定编码,字节流在文件 ...

  6. rest_frameword学前准备

    CBV CBV(class base views) 就是在视图里使用类处理请求. Python是一个面向对象的编程语言,如果只用函数来开发,有很多面向对象的优点就错失了(继承.封装.多态).所以Dja ...

  7. hdu 1227(动态规划)

    Fast Food Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total S ...

  8. 关于Promise 简单使用理解

    在学一个新的知识的时候,我的总结是首先要具备相关的基础知识,其次就是可以静下心来能看进去去理解,看一两遍不懂,就看四五遍,甚至六七遍,每一遍都认真努力理解,总会学会的. Promise是一个构造函数, ...

  9. Nginx 的安装配置入门(mac)

    1.安装Nginx服务器: 执行命令 brew install nginx 安装完以后,可以在终端输出的信息里看到一些配置路径: /usr/local/etc/nginx/nginx.conf (配置 ...

  10. MapReduce 编程模板

    1.MapReduce 编程模型的5个步骤: 1)迭代,将输入数据解析成 key/value 对: 2)将解析的 key/value经过Map处理映射成另一组key/value对: 3)根据key进行 ...