zoukankan      html  css  js  c++  java
  • Spring Boot 中 Druid 的监控页面配置

    Druid的性能相比HikariCp等其他数据库连接池有一定的差距,但是数据库的相关属性的监控,别的连接池可能还追不上,如图:

    今天写一下 Spring Boot 中监控页面的配置,我是直接将seata中的相关Druid的Servlet 和 Filter的配置粘贴出来。

    import org.springframework.boot.web.servlet.FilterRegistrationBean;
    import org.springframework.boot.web.servlet.ServletRegistrationBean;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    
    import com.alibaba.druid.support.http.StatViewServlet;
    import com.alibaba.druid.support.http.WebStatFilter;
    
    @Configuration
    public class DruidConfig {
    
        /**
         * 注册一个StatViewServlet
         *
         * @return servlet registration bean
         */
        @Bean
        public ServletRegistrationBean druidStatViewServlet() {
            ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(
                new StatViewServlet(), "/druid/*");
    
            servletRegistrationBean.addInitParameter("loginUsername", "admin");
            servletRegistrationBean.addInitParameter("loginPassword", "123456");
            servletRegistrationBean.addInitParameter("resetEnable", "false");
            return servletRegistrationBean;
        }
    
        /**
         * 注册一个:filterRegistrationBean
         *
         * @return filter registration bean
         */
        @Bean
        public FilterRegistrationBean druidStatFilter() {
    
            FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(
                new WebStatFilter());
    
            // 添加过滤规则.
            filterRegistrationBean.addUrlPatterns("/*");
    
            // 添加不需要忽略的格式信息.
            filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
            return filterRegistrationBean;
        }
    }

    以供参考

  • 相关阅读:
    Linux权限及归属管理
    Linux账户管理
    随笔记录 磁盘坏道故障 2019.8.7
    随笔记录 MBR扇区故障系统备份与还原 2019.8.7
    随笔记录 grub引导故障修复 2019.8.7
    随笔记录 综合训练 2019.8.5
    随笔记录 磁盘配额2019.8.2
    随笔记录 2019.7.31
    随笔记录 2019.7.31
    随笔记录 linux命令 2019.7.29
  • 原文地址:https://www.cnblogs.com/yidiandhappy/p/10977923.html
Copyright © 2011-2022 走看看