项目场景:
SpringBoot 整合Druid数据源SQL监控不显示
问题描述:
明明使用Druid数据源运行相关的SQL语句 但是druid监控页面没有显示记录 :
因为新版Druid不兼容旧版本的yml配置
解决方案:
使用以下监控配置
server:
port: 8080
spring:
mvc:
format:
date-time: yyyy-MM-dd HH:mm:ss
thymeleaf:
cache: false
messages:
basename: i18n.index
datasource:
username: root
password: 123456
url: jdbc:mysql://localhost:3306/problemsys?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&useSSL=true
driver-class-name: com.mysql.cj.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
druid:
# 配置初始化大小、最小、最大线程数
initialSize: 5
minIdle: 5
# CPU核数+1,也可以大些但不要超过20,数据库加锁时连接过多性能下降
maxActive: 20
# 最大等待时间,内网:800,外网:1200(三次握手1s)
maxWait: 60000
timeBetweenEvictionRunsMillis: 60000
# 配置一个连接在池中最大空间时间,单位是毫秒
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1 FROM DUAL
testWhileIdle: true
# 设置从连接池获取连接时是否检查连接有效性,true检查,false不检查
testOnBorrow: true
# 设置从连接池归还连接时是否检查连接有效性,true检查,false不检查
testOnReturn: true
# 可以支持PSCache(提升写入、查询效率)
poolPreparedStatements: true
# 配置控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
# 状态监控
filter:
stat:
enabled: true
db-type: mysql
log-slow-sql: true
slow-sql-millis: 2000
# 监控过滤器
web-stat-filter:
enabled: true
exclusions:
- "*.js"
- "*.gif"
- "*.jpg"
- "*.png"
- "*.css"
- "*.ico"
- "/druid/*"
# 保持长连接
keepAlive: true
maxPoolPreparedStatementPerConnectionSize: 20
useGlobalDataSourceStat: true
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500