数据连接池监控配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
username: ${MYSQL_USER:root}
password: ${MYSQL_PWD:1111}
url: jdbc:mysql://${MYSQL_HOST:127.0.0.1}:${MYSQL_PORT:3306}/${MYSQL_DB:crm}?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true&socketTimeout=60000&connectTimeout=10000
# 初始化连接数,应用启动时创建的数据库连接数量
initial-size: 10
# 最小空闲连接数,连接池长期保持的最少连接数量
min-idle: 10
# 最大活跃连接数,连接池同时最多允许创建的数据库连接数量
max-active: 15
# 获取连接最大等待时间(毫秒)
max-wait: 30000
# 数据库连接有效性检测SQL
validation-query: SELECT 1
# 获取连接时是否检测连接有效性
test-on-borrow: false
# 归还连接时是否检测连接有效性
test-on-return: false
# 空闲连接检测
test-while-idle: true
# 开启连接保活
keep-alive: true
# 空闲连接检测周期
time-between-eviction-runs-millis: 60000
# 空闲连接超过10分钟回收
min-evictable-idle-time-millis: 600000
# 单个连接最大生命周期30分钟
phy-timeout-millis: 1800000
# 是否开启连接泄漏回收
remove-abandoned: false
# Druid监控页面
stat-view-servlet:
enabled: true
url-pattern: /druid/*
login-username: admin
login-password: "你的强密码"
allow: ""
# Web请求监控
web-stat-filter:
enabled: true
url-pattern: /*
exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
# Druid过滤器
filter:
stat:
enabled: true
# 开启慢SQL记录
log-slow-sql: true
# 慢SQL阈值 3秒
slow-sql-millis: 3000
# SQL合并统计
merge-sql: true
wall:
enabled: true
config:
# 允许多SQL执行
multi-statement-allow: true
1
2
3
4
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
</dependency>

访问http://localhost:6060/druid/index.html