spring boot1.5.2.RELEASE集成javameloady
spring boot1.5.2.RELEASE集成javameloady
tianxia007 发表于5个月前
spring boot1.5.2.RELEASE集成javameloady
  • 发表于 5个月前
  • 阅读 25
  • 收藏 1
  • 点赞 0
  • 评论 0

腾讯云 新注册用户 域名抢购1元起>>>   

javameloady maven引入版本:

<dependency>
            <groupId>net.bull.javamelody</groupId>
            <artifactId>javamelody-core</artifactId>
            <version>1.68.1</version>
</dependency>

如果启动报错:代理相关异常,添加以下坐标:

<dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
</dependency>
JavaMelodyConfiguration:
public class JavaMelodyConfiguration implements ServletContextInitializer {

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        servletContext.addListener(new SessionListener());
    }

    @Bean
    public FilterRegistrationBean javaMelody() {
        final FilterRegistrationBean javaMelody = new FilterRegistrationBean();
        final MonitoringFilter filter = new MonitoringFilter();
        filter.setApplicationType("Spring boot");

        javaMelody.setFilter(filter);
        javaMelody.setAsyncSupported(true);
        javaMelody.setName("javamelody");
        javaMelody.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC);

        // see the list of parameters:
        // https://github.com/javamelody/javamelody/wiki/UserGuide#6-optional-parameters
        javaMelody.addInitParameter(Parameter.LOG.getCode(), Boolean.toString(true));
        // to exclude images, css, fonts and js urls from the monitoring:
        javaMelody.addInitParameter(Parameter.URL_EXCLUDE_PATTERN.getCode(), "/static/.{0,}");
        // to add basic auth:
        javaMelody.addInitParameter(Parameter.AUTHORIZED_USERS.getCode(), "admin:1");
        // to change the default storage directory:
        File f = new File("./javamelody/");
        if (!f.exists()) f.mkdir();
        System.out.println("javamelody 绝对路径:" + f.getAbsolutePath() + "___" + f.getPath());
        javaMelody.addInitParameter(Parameter.STORAGE_DIRECTORY.getCode(), f.getAbsolutePath());

        //javaMelody.addInitParameter(Parameter.JPA_TRANSFORM_PATTERN.getCode(), "./javamelody");

        javaMelody.addInitParameter(Parameter.DATASOURCES.getCode(), "dataSource");

        javaMelody.addUrlPatterns("/*");
        return javaMelody;
    }

    //
//    // Note: if you have auto-proxy issues, you can add the following dependency in your pom.xml:
//    // <dependency>
//    //   <groupId>org.aspectj</groupId>
//    //   <artifactId>aspectjweaver</artifactId>
//    // </dependency>
//    @Bean
//    public DefaultAdvisorAutoProxyCreator getDefaultAdvisorAutoProxyCreator() {
//         return new DefaultAdvisorAutoProxyCreator();
//    }
//
    // monitoring of jdbc datasources:
    @Bean
    public SpringDataSourceBeanPostProcessor monitoringDataSourceBeanPostProcessor() {
        final SpringDataSourceBeanPostProcessor processor = new SpringDataSourceBeanPostProcessor();
        processor.setExcludedDatasources(null);
        return processor;
    }

    //
//    // monitoring of beans or methods having @MonitoredWithSpring:
    @Bean
    public MonitoringSpringAdvisor monitoringAdvisor() {
        final MonitoringSpringAdvisor interceptor = new MonitoringSpringAdvisor();
        interceptor.setPointcut(new MonitoredWithAnnotationPointcut());
        return interceptor;
    }
//
//    // monitoring of all services and controllers (even without having @MonitoredWithSpring):
////    @Bean
//    public MonitoringSpringAdvisor springServiceMonitoringAdvisor() {
//        final MonitoringSpringAdvisor interceptor = new MonitoringSpringAdvisor();
//        interceptor.setPointcut(new AnnotationMatchingPointcut(org.springframework.stereotype.Service.class));
//        return interceptor;
//    }

    @Bean
    public MonitoringSpringAdvisor springControllerMonitoringAdvisor() {
        final MonitoringSpringAdvisor interceptor = new MonitoringSpringAdvisor();
        interceptor.setPointcut(new AnnotationMatchingPointcut(org.springframework.stereotype.Controller.class));
        return interceptor;
    }


    @Bean
    public MonitoringSpringAdvisor springRestControllerMonitoringAdvisor() {
        final MonitoringSpringAdvisor interceptor = new MonitoringSpringAdvisor();
        interceptor.setPointcut(new AnnotationMatchingPointcut(RestController.class));
        return interceptor;
    } }

集成后效果图:(图片单独页面打开可看清)

 

标签: 监控 javameloady
共有 人打赏支持
tianxia007
粉丝 20
博文 3
码字总数 486
作品 2
×
tianxia007
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: