druid慢sql监控

1、引入依赖


    com.alibaba
    druid-spring-boot-starter
    ${druid.version}

2、application.yml配置

spring:
  datasource:
    druid: # 使用druid数据源
      filter:
        stat:
          slow-sql-millis: 1000 #slowSqlMillis的缺省值为3000,也就是3秒。
          log-slow-sql: true #日志输出执行慢的SQL
          enabled: true
          db-type: mysql

3、logback.xml配置



    ${LOG_HOME:-d:/}logs/slow_sql/slow_sql.log
    
        ${LOG_HOME:-d:/}logs/slow_sql/slow_sql-%d{yyyy-MM-dd}.%i.log
        
        60
        
            5MB
        
    
    
        [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n
        
    
    
        ERROR
        ACCEPT
        DENY
    



    
    
    

4、错误日志

根据logback.xml配置,会生产慢sql日志slow_sql.log

[ERROR] 2022-08-30 22:44:15.651 [http-nio-8080-exec-1] c.a.druid.filter.stat.StatFilter - slow sql 4698 millis. SELECT  id,name,no,create_time,update_time  FROM user[]
[ERROR] 2022-08-30 22:57:15.183 [http-nio-8080-exec-2] c.a.druid.filter.stat.StatFilter - slow sql 3645 millis. SELECT  id,name,no,create_time,update_time  FROM user[]

你可能感兴趣的:(spring,数据库,mysql,sql,java,mybatis)