Download JavaMelody and javamelody
I haven't paid much attention to javaMelody.
When I write something, I want to get some monitoring information, so I loaded javaMelody into it.
I have read almost all the documents in French. Here I will record some common configurations.
Add the following dependencies first:
<dependency> <groupId>net.bull.javamelody</groupId> <artifactId>javamelody-core</artifactId> <version>1.50.0</version></dependency>
The most basic configuration:net.bull.javamelody.MonitoringFilterAndnet.bull.javamelody.SessionListener
The two must have the MonitoringFilter Servlet Filter used for monitoring, which must be declared in the web. xml of the webapp.
SessionListener is used to listen to HTTP sessions and Servlet Context. It must be declared in web. xml of webapp.
/** * Filtre de servlet pour le monitoring. * C'est la classe de ce filtre qui doit être déclarée dans le fichier web.xml de la webapp. * @author Emeric Vernat */public class MonitoringFilter implements Filter{ //...}
The configuration in web. xml is as follows:
<filter> <filter-name>monitoring</filter-name> <filter-class>net.bull.javamelody.MonitoringFilter</filter-class></filter><filter-mapping> <filter-name>monitoring</filter-name> <url-pattern>/*</url-pattern></filter-mapping><listener> <listener-class>net.bull.javamelody.SessionListener</listener-class></listener>
If the mvc framework uses struts, javaMelody providesnet.bull.javamelody.StrutsInterceptor.
/** * Interceptor Struts 2 pour avoir les temps moyens des actions Struts. * {@link StrutsInterceptor "http://struts.apache.org/2.1.6/docs/interceptors.html"} * @author Emeric Vernat */public final class StrutsInterceptor extends AbstractInterceptor{ //..}
Integrated with AbstractInterceptor, you can directly put it on reg in the interceptor tag of struts2:
<package name="default" extends="struts-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>
For data source monitoring, although the author providesnet.bull.javamelody.JdbcDriverBut usually dbcp, c3p0, and so on, and then inject it into TransactionMananger for point transaction management.
Usenet.bull.javamelody.SpringDataSourceFactoryBeanThe data source is monitored by the Monitoring Agent. For example, inject the declared Data source:
<bean id="mainDataSource" class="net.bull.javamelody.SpringDataSourceFactoryBean"> <property name="targetName" value="_mainDataSource" /></bean>
After this configuration, I tried to execute an SQL statement and it did monitor it. But what I declarenet.bull.javamelody.MonitoringSpringAdvisorBut nothing is recorded.
This is what we are talking about:
For aop, you can usenet.bull.javamelody.MonitoringSpringAdvisor.
The official website provides three configuration methods:
<bean id="facadeMonitoringAdvisor" class="net.bull.javamelody.MonitoringSpringAdvisor"> <property name="pointcut"> <bean class="org.springframework.aop.support.JdkRegexpMethodPointcut"> <property name="patterns"> <list> <value>com.xyz.someapp.service.MonitoringPointcut0.*</value> <value>com.xyz.someapp.service.MonitoringPointcut1.*</value> <value>com.xyz.someapp.service.MonitoringPointcut2.*</value> </list> </property> </bean> </property></bean>
This configuration does not take effect.
If the data source is configured in spring contextclasspath:net/bull/javamelody/monitoring-spring.xmlJoincontextConfigLocation.
But I did not add it. The problem is that I did not care much about the SQL Execution.
But this time we didn't monitor spring, we need to add this.
<context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:net/bull/javamelody/monitoring-spring.xml classpath*:/applicationContext*.xml </param-value></context-param>
So what is this monitoring-spring.xml?
Let's take a look at his content:
<?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: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/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <bean id="monitoringAdvisor" class="net.bull.javamelody.MonitoringSpringAdvisor"> <property name="pointcut"> <bean class="net.bull.javamelody.MonitoredWithAnnotationPointcut"/> </property> </bean> <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/> <bean id="springDataSourceBeanPostProcessor" class="net.bull.javamelody.SpringDataSourceBeanPostProcessor"> <!-- <property name="excludedDatasources"> <set> <value>excludedDataSourceName</value> </set> </property> --> </bean> <!-- <bean id="wrappedDataSource" class="net.bull.javamelody.SpringDataSourceFactoryBean"> <property name="targetName" value="targetDataSource" /> </bean> --></beans>
MonitoringSpringAdvisor inherits the default DefaultPointcutAdviso and sets an Advice -- MonitoringSpringInterceptor in its constructor to simplify the configuration.
MonitoredWithAnnotationPointcut is the implementation of Pointcut, which allows all MonitoredWithSpring to use MonitoredWithSpring annotations and all classes to pass.
In addition, I use Quartz in the timing task framework. If it is only Quartz, JavaMelody will automatically monitor the task without any configuration.
However, if QuartzJavaMelody of spring scheduling is used to provide... in fact, it does not provide anything.
The key is that org. springframework. scheduling. quartz. SchedulerFactoryBean containsexposeSchedulerInRepositoryAlthough it is not recommended in the annotations, It is okay if the spring version is new enough.
For spring Z integrated with spring, you only need to set this attribute to true (default value: false ).
Then, go to monitoring and display the following: