当前位置:网站首页>Druid configuration and monitoring
Druid configuration and monitoring
2022-07-20 12:41:00 【thoughtCodes】
1.drid To configure :
To configure The default value explain
name The point of configuring this property is , If there are multiple data sources , Monitoring can be distinguished by name . If not configured , Will generate a name , The format is :“DataSource-” + System.identityHashCode(this)
jdbcUrl Connected to the database url, Different databases are different . for example : 1)mysql : jdbc:mysql://10.20.153.104:3306/druid 2)oracle : jdbc:oracle:thin:@10.20.149.85:1521:ocnauto
username User name to connect to the database
password Password to connect to the database . If you don't want the password written directly in the configuration file , have access to ConfigFilter. Look here in detail :https://github.com/alibaba/druid/wiki/%E4%BD%BF%E7%94%A8ConfigFilter
driverClassName according to url Automatic identification This item can be matched or not , If you don't configure druid Will be based on url Automatic identification dbType, Then choose the appropriate driverClassName( It is recommended to configure )
initialSize 0 Number of physical connections established during initialization . Initialization occurs in the display call init Method , Or for the first time getConnection when
maxActive 8 Maximum number of connection pools
maxIdle 8 No longer in use , Configuration has no effect
minIdle Minimum number of connection pools
maxWait Maximum wait time when getting a connection , Unit millisecond . Configured with maxWait after , Fair lock is enabled by default , Concurrency efficiency will decrease , If necessary, it can be configured through useUnfairLock The attribute is true Use unfair locks .
poolPreparedStatements false Whether the cache preparedStatement, That is to say PSCache.PSCache Great improvement in database performance supporting cursors , for instance oracle. stay mysql The next suggestion is to close .
maxOpenPreparedStatements -1 To enable the PSCache, Must be configured greater than 0, When more than 0 when ,poolPreparedStatements Auto trigger changed to true. stay Druid in , No existence Oracle Next PSCache The problem of using too much memory , You can configure this value to be larger , for instance 100
validationQuery Used to check whether the connection is valid sql, The requirement is a query statement . If validationQuery by null,testOnBorrow、testOnReturn、testWhileIdle It doesn't work .
testOnBorrow true Execute on connection request validationQuery Check whether the connection is valid , This configuration will degrade performance .
testOnReturn false Execute... When returning the connection validationQuery Check whether the connection is valid , This configuration will degrade performance
testWhileIdle false Recommended configuration is true, No performance impact , And ensure safety . Check when applying for connection , If the free time is greater than timeBetweenEvictionRunsMillis, perform validationQuery Check whether the connection is valid .
timeBetweenEvictionRunsMillis There are two meanings : 1) Destroy The thread will detect the connection interval 2) testWhileIdle On the basis of , See in detail testWhileIdle Description of the property
numTestsPerEvictionRun No longer use , One DruidDataSource Only one... Is supported EvictionRun
minEvictableIdleTimeMillis
connectionInitSqls When the physical connection is initialized sql
exceptionSorter according to dbType Automatic identification
filters Property type is string , Configure the extension by alias , Common plug-ins are : For monitoring statistics filter:stat, It's for the log filter:log4j, defense sql Injected filter:wall
proxyFilters The type is List<com.alibaba.druid.filter.Filter>, If it is configured at the same time filters and proxyFilters, It's a combination relationship , It's not a replacement relationship
Two 、 Open page statistics
com.alibaba druid-spring-boot-starter 1.1.9 Configure the corresponding monitoring :
datasource:
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://localhost:3306/dwsurvey?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&serverTimezone=Asia/Shanghai
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
druid:
Number of physical connections established during initialization
initial-size: 5
Minimum number of connection pools
min-idle: 5
Maximum number of connection pools
max-active: 20
Maximum wait time when getting a connection , Unit millisecond
max-wait: 5000
# Condition monitoring
filter:
stat:
enabled: true
db-type: mysql
log-slow-sql: true
slow-sql-millis: 2000
# Monitoring filters
web-stat-filter:
enabled: true
exclusions:
- "*.js"
- "*.gif"
- "*.jpg"
- "*.png"
- "*.css"
- "*.ico"
- "/druid/*"
# druid Monitoring the page
stat-view-servlet:
Whether to turn on monitoring
enabled: true
Monitoring paths
url-pattern: /druid/*
Can I reset the data
reset-enable: false
The login password
login-password: root
Login name
login-username: root
validation-query: "SELECT 1 FROM DUAL "
Visual page address : http://localhost:8080/druid/sql.html
3、 ... and . Single package method :
If the imported package is single druid You need to configure one for your package bean
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
import com.alibaba.druid.wall.WallConfig;
import com.alibaba.druid.wall.WallFilter;
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 org.springframework.jdbc.datasource.DataSourceTransactionManager;
import javax.sql.DataSource;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@Configuration
public class DruidConfiguration {
@Bean
public ServletRegistrationBean druidServlet() {
// establish servlet Registered entity
ServletRegistrationBean<Servlet> bean = new ServletRegistrationBean<>(new StatViewServlet(),"/druid/*");
// Set up ip White list
//servletRegistrationBean.addInitParameter("allow","127.0.0.1");
// Set up ip The blacklist , If allow And deny Co existing ,deny Prior to the allow
//servletRegistrationBean.addInitParameter("deny","192.168.0.250");
// Set up console administration user
servletRegistrationBean.addInitParameter("loginUsername","druid");
servletRegistrationBean.addInitParameter("loginPassword","123456");
// Can I reset the data
servletRegistrationBean.addInitParameter("resetEnable","false");
bean.setInitParameters(map);
return bean;
}
@Bean
public FilterRegistrationBean filterRegistrationBean() {
FilterRegistrationBean<Filter> bean = new FilterRegistrationBean<>();
// Create filters
bean.setFilter(new WebStatFilter());
Map<String,String> map = new HashMap<>();
// Ignore the form of filtering
map.put("exclusions","*.js,*.css,/druid/*");
// Set filter path
bean.setUrlPatterns(Arrays.asList("/*"));
bean.setInitParameters(map);
return bean;
}
@Bean
public WallFilter wallFilter(){
WallFilter wallFilter = new WallFilter();
wallFilter.setConfig(wallConfig());
return wallFilter;
}
@Bean
public WallConfig wallConfig(){
WallConfig wallConfig = new WallConfig();
wallConfig.setMultiStatementAllow(true);
// Allow multiple statements to be executed at one time
wallConfig.setNoneBaseStatementAllow(true);
// Whether other statements other than the above basic statements are allowed
wallConfig.setStrictSyntaxCheck(false);
// Whether strict grammar checking is carried out
return wallConfig;
}
@Bean(name="dataSource")
public DataSource dataSource(){
return new DruidDataSource();
}
// Configure things Manager
@Bean(name="transactionManager")
public DataSourceTransactionManager transactionManager(){
return new DataSourceTransactionManager(dataSource());
}
}
There are some springboot Project startup opens druid The visual interface is normal , But I can't see what is being monitored sql sentence , At this time we are jvm Configure a command when starting :
-Ddruid.filters=mergeStat -Ddruid.useGlobalDataSourceStat=true
Turn on druid Global monitoring of , That's it !
————————————————
Recommended reading :
Link to the original text :https://blog.csdn.net/qq_36364521/article/details/121535424
边栏推荐
- SLT 定义vetctor对象,vector构造函数
- News Express | congratulations to engineer Xiao Xiaorong for obtaining Domo professional certification!
- notepad++如何取消空行
- Flask request data and get response
- apt的学习
- Weekly recommended short videos: put forward higher requirements for the elastic computing power of cloud computing
- A good product needs "emotional value"
- [HDU 6095] Rikka with Competition
- 腾讯大咖分享 | 腾讯Alluxio(DOP)在金融场景的落地与优化实践
- [wechat applet] button (90/100)
猜你喜欢
Part 15: SPI serial communication protocol of stm32
Read the paper: (yolov1) you only look once:unified, real time object detection
Why psp22 is important to Polkadot ecosystem
Filter setting of can
A good product needs "emotional value"
Rancher安装部署及基本使用
NoSQL-Mongodb
腾讯大咖分享 | 腾讯Alluxio(DOP)在金融场景的落地与优化实践
Understand 25 neural network models - typical models of artificial neural networks
[postponed to December] 2022 International Symposium on Cyber Security (csw2022)
随机推荐
Keep the number of float type to 2 decimal places
STL vector的输出
新蓝海“硬防晒”,千亿市场“遮不住”了
tar. GZ file repair
How to find an internship? How to prepare?
NFT game interoperability: technology is not a roadblock
Synonym converter software
【通信】【2】《宽带太赫兹通信技术》的笔记和一些简单的词汇的意思(误
Understand the MySQL architecture design in one article, and don't worry about the interviewer asking too much
解决:配置、路径完全没错 gateway就是访问不了
《强化学习基础》1
News Express | congratulations to engineer Xiao Xiaorong for obtaining Domo professional certification!
Starbucks may close more U.S. stores in the future due to concerns about the safety of employees
出于对员工人身安全的担忧 星巴克未来可能关闭更多美国门店
What is the gold content of PMP certificate? Is it worth taking the exam?
Crontab execution time setting
[postponed to December] 2022 International Symposium on Cyber Security (csw2022)
IDEA 连接h2数据库报错
2022 latest cloud development to watermark applet source code
Reflective Decoding: Beyond Unidirectional Generation with Off-the-Shelf Languag