使用JavaMelody监控spring、struts
lple68
9年前
引言:JavaMelody的目的是监控Java或Java EE应用服务器在QA和生产环境。它不是一个用来模拟用户要求的工具而是一个来监控应用程序和计算统计用户操作情况的应用程序。更多详细内容请看JavaMelody。
1. 下载zip包:
http://javamelody.googlecode.com/files/javamelody-1.47.0.zip
2. 解压zip包后添加所需jar包到项目中:
javamelody.jar,jrobin-1.5.9.1.jar
3. 添加monitoring配置到Web.xml文件:
<context-param> <param-name> contextConfigLocation</param-name> <param-value> classpath:applicationContext*.xml<!--Spring配置文件--> classpath:net/bull/javamelody/monitoring-spring.xml<!--和spring集成时添加--> </param-value> </context-param> <filter> <filter-name>monitoring</filter-name> <filter-class>net.bull.javamelody.MonitoringFilter</filter-class> <init-param> <param-name>log</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>monitoring</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class> net.bull.javamelody.SessionListener</listener-class> </listener>
4. 与struts2集成时新建struts-monitoring.xml文件:
<? xml version= "1.0" encoding ="UTF-8" ?> <! DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd" > <struts> <package name= "default" extends ="struts-default,json-default" > <interceptors> <interceptor name ="monitoring" class ="net.bull.javamelody.StrutsInterceptor" /> <interceptor-stack name ="myStack" > <interceptor-ref name ="monitoring" /> <interceptor-ref name ="defaultStack" /> </interceptor-stack> </interceptors> <default-interceptor-ref name ="myStack" /> </package> </struts>
5. 其他struts配置文件继承default和引用myStack,如下所示:
<package name ="*" extends ="default" namespace ="/" > <global-results> <result name= "error" >page/error.html </result> </global-results> <action name= "*_*" class ="{1}Action" method ="{2}" > <result name= "index" >page/{1}/index.html </result> <result name= "json" type ="json" >json_result </result> <interceptor-ref name ="myStack" /> </action> </package>
6. 与Spring集成时添加如下信息对接口进行监控:
<bean id= "facadeMonitoringAdvisor" class="net.bull.javamelody.MonitoringSpringAdvisor" > <property name ="pointcut" > <bean class="org.springframework.aop.support.JdkRegexpMethodPointcut" > <property name ="pattern" value="org.melody.*.*.service.*" /><!--正则表达式--> </bean> </property> </bean>
7. 访问monitoring地址:
http://<ipaddr>:<host>/projectname/monitoring
效果图如下: