新版druid數據源驅動的SQL監控如果用以前的老版本配置是無法監控到SQL的:
application.yml
spring: datasource: druid: filters: - stat - wall - log4j
啟動應用之后訪問druid監控頁面,除了SQL相關的頁面都正常工作,但是訪問SQL監控頁面時沒有看到SQL記錄。
查看監控頁面 數據源 菜單發現 filter類名 顯示的是空,估計是filter配置有問題導致。
查閱官方文檔發現filter配置有變更,改成以下形式即可統計SQL,同時在數據源頁面 filter類名 會顯示正常。
application.yml
spring: datasource: druid: initial-size: 5 min-idle: 5 max-active: 20 max-wait: 5000 # 狀態監控 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/*" # druid 監控頁面 stat-view-servlet: enabled: true url-pattern: /druid/* reset-enable: false login-username: root login-password: root
數據源filter類名:com.alibaba.druid.filter.stat.StatFilter
轉載地址:https://segmentfault.com/a/1190000019718506?utm_source=tag-newest