前言
JavaMelody的目标是监视QA和生产环境中的Java或Java EE应用程序。它不是模拟用户请求的工具,而是根据用户对应用程序的使用情况来测量和计算有关应用程序实际操作的统计信息的工具。
github地址链接
代码部分
- pom.xml
<!-- https://mvnrepository.com/artifact/net.bull.javamelody/javamelody-core -->
<!-- javamelody-core -->
<dependency>
<groupId>net.bull.javamelody</groupId>
<artifactId>javamelody-core</artifactId>
<version>1.85.0</version>
</dependency>
<!--JavaMelody监控PDF格式文件导出 可以不加-->
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.7</version>
</dependency>
- JavaMelody配置类
import net.bull.javamelody.MonitoringFilter;
import net.bull.javamelody.Parameter;
import net.bull.javamelody.SessionListener;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* QY
* JavaMelody配置类
*/
@Configuration
public class JavaMelodyConfiguration {
@Bean
public FilterRegistrationBean monitorFilter() {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new MonitoringFilter());
// filterRegistrationBean.addInitParameter(Parameter.QUARTZ_DEFAULT_LISTENER_DISABLED.getCode(), "true");
filterRegistrationBean.addUrlPatterns("/*");
// to add basic auth:
// 这个是添加http basic认证的账号密码
String user = "admin";
String pwd = "password";
filterRegistrationBean.addInitParameter(Parameter.AUTHORIZED_USERS.getCode(), user+":"+pwd);
// to change the default "/monitoring" path
// 修改默认路径
filterRegistrationBean.addInitParameter(Parameter.MONITORING_PATH.getCode(), "/open/sys/monitoring");
// filterRegistrationBean.setName("monitoring");
return filterRegistrationBean;
}
@Bean
public ServletListenerRegistrationBean sessionListener() {
ServletListenerRegistrationBean servletListenerRegistrationBean = new ServletListenerRegistrationBean();
servletListenerRegistrationBean.setListener(new SessionListener());
return servletListenerRegistrationBean;
}
}
展示