现在的位置: 首页 > 编程语言 > 正文

基于javamelody监控springboot项目过程详解

2020年02月13日 编程语言 ⁄ 共 1773字 ⁄ 字号 评论关闭

JavaMelody是用来在QA和实际运行生产环境中监控Java或Java EE应用程序服务器的一个开源框架。它不是一个工具来模拟来自用户的请求,而是一个测量和计算用户在实际操作中应用程序的使用情况的工具,并以图表的形式显示,图表可以按天,周,月,年或自定义时间段查看。

JavaMelody基础的监控包括Java内存和Java CPU使用情况,用户Session数量,JDBC连接数,和http请求、sql请求、jsp页面与业务接口方法(EJB3、Spring、 Guice)的执行数量,平均执行时间,错误百分比等。如果要监控Jenkins,JIRA,Sonar等等一些,需要另外安装对应的插件,还有一些高级文档用于高级配置。此文仅以JavaMelody v1.63.0版本演示基础功能的集成及使用,更多功能请深入研究官方文档。

1. 相关链接

官方文档 https://github.com/javamelody/javamelody/wiki/UserGuide

下载地址https://github.com/javamelody/javamelody/releases

2. 基础集成

1.pom中加入

<!-- https://mvnrepository.com/artifact/net.bull.javamelody/javamelody-core --> <dependency> <groupId>net.bull.javamelody</groupId> <artifactId>javamelody-core</artifactId> <version>1.79.0</version> </dependency>

2.springboot启动文件中加入

public class App { public static void main(String[] args) { SpringApplication.run(App.class, args); } /** * 配置javamelody监控 spring boot 会按照order值的大小,从小到大的顺序来依次过滤 */ @Bean @Order(Integer.MAX_VALUE - 1) public FilterRegistrationBean monitoringFilter() { FilterRegistrationBean registration = new FilterRegistrationBean(); registration.setFilter(new MonitoringFilter()); registration.addUrlPatterns("/*"); registration.setName("monitoring"); return registration; } /** * 配置javamelody监听器sessionListener */ @Bean public ServletListenerRegistrationBean<SessionListener> servletListenerRegistrationBean() { ServletListenerRegistrationBean<SessionListener> slrBean = new ServletListenerRegistrationBean<SessionListener>(); slrBean.setListener(new SessionListener()); return slrBean; }}

3,现在可以部署程序启动服务器,在浏览器打开http://<host>/<context>/monitoring。<host>:为你的主机名+端口地址,<context>:为你的应用配置地址。应该可以看到如下界面:

3. Spring方法级监控

前提是使用monitoring-spring.xml文件(不做修改),然后在需要监控的方法上使用@MonitoredWithSpring注解即可。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

本文标题: 基于javamelody监控springboot项目过程详解

以上就上有关基于javamelody监控springboot项目过程详解的全部内容,学步园全面介绍编程技术、操作系统、数据库、web前端技术等内容。

抱歉!评论已关闭.