当前位置:网站首页>Talk about how to use p6spy for SQL monitoring
Talk about how to use p6spy for SQL monitoring
2022-07-03 05:19:00 【Linyb geek Road】
Preface
1、p6spy brief introduction
P6Spy It's a framework , No code changes need to be made to existing applications , You can seamlessly intercept and record database data . adopt P6Spy We can SQL Statement to intercept , Equivalent to one SQL Statement logger , In this way, we can use it for relevant analysis , For example, performance analysis
2、 Realization principle
p6spy Hijack the data source of the application , The application operation database is actually calling p6spy Data source ,p6spy Hijack to what needs to be executed sql perhaps hql After statements like , He calls one himself realDatasource, Then operate the database
3、 Relevant official documents
github:https://github.com/p6spy/p6spy
Official website :https://p6spy.readthedocs.io/en/latest/index.html
p6spy Use
1、 In the project pom Introduce related GAV
<dependency> <groupId>p6spy</groupId> <artifactId>p6spy</artifactId> <version>${p6spy.version}</version> </dependency>2、 Switch between in the project jdbc Drivers and data sources
Change to the following
spring: datasource: type: com.alibaba.druid.pool.DruidDataSource driverClassName: ${DRIVER_CALSS_NAME:com.p6spy.engine.spy.P6SpyDriver} url: ${DATASOURCE_URL:jdbc:p6spy:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai} username: ${DATASOURCE_USERNAME:root} password: ${DATASOURCE_PWD:123456}3、 stay resource Add under directory spy.properties
The configuration is as shown in the following example
#3.2.1 Above use modulelist=com.baomidou.mybatisplus.extension.p6spy.MybatisPlusLogFactory,com.p6spy.engine.outage.P6OutageFactory#3.2.1 The following uses or does not configure #modulelist=com.p6spy.engine.logging.P6LogFactory,com.p6spy.engine.outage.P6OutageFactory# Custom log printing #logMessageFormat=com.baomidou.mybatisplus.extension.p6spy.P6SpyLoggerlogMessageFormat=com.github.lybgeek.p6spy.extentsion.CustomP6SpyLogger# Log output to the console #appender=com.baomidou.mybatisplus.extension.p6spy.StdoutLogger# Use the logging system to record sql#appender=com.p6spy.engine.spy.appender.Slf4JLoggerappender=com.github.lybgeek.p6spy.extentsion.CustomStdoutLogger# Set up p6spy driver agent deregisterdrivers=true# Cancel JDBC URL Prefix useprefix=true# Configuration record Log exception , The result sets that can be removed are error,info,batch,debug,statement,commit,rollback,result,resultset.excludecategories=info,debug,result,commit,resultset# Date format dateformat=yyyy-MM-dd HH:mm:ss# The actual drive can be multiple #driverlist=org.h2.Driver# Whether to turn on slowly SQL Record outagedetection=true# slow SQL Record standard 2 second outagedetectioninterval=24、 Custom log format 【 Optional 】
public class CustomP6SpyLogger implements MessageFormattingStrategy { /** * Sql Log formatting * * @param connectionId: Connect ID * @param now: current time * @param elapsed: Spend time * @param category: Category * @param prepared: precompile SQL * @param sql: Final executed SQL * @param url: Database connection address * @return Format log results */ @Override public String formatMessage(int connectionId, String now, long elapsed, String category, String prepared, String sql, String url) { return StringUtils.isNotBlank(sql) ? " Time consuming :" + elapsed + " ms " + now + "\n perform SQL:" + sql.replaceAll("[\\s]+", " ") + "\n" : ""; }}stay spy.properties Configure custom log format in
logMessageFormat=com.github.lybgeek.p6spy.extentsion.CustomP6SpyLogger5、 Custom log output 【 Optional 】
public class CustomStdoutLogger extends com.p6spy.engine.spy.appender.StdoutLogger{ @Override public void logText(String text) { System.out.println("sql:" + text); }}stay spy.properties Configure custom log output
appender=com.github.lybgeek.p6spy.extentsion.CustomStdoutLogger6、 Test and observe the console output
sql: Time consuming :1 ms 2022-05-10 11:38:34 perform SQL:SELECT id,username,password,fullname,mobile,email FROM t_usersummary
p6spy According to sql Execution efficiency analysis of sql Yes sql To optimize , But because p6spy Will have a certain impact on performance , Therefore, it is not suitable for use in a formal environment . Besides, it's about p6spy For more detailed configuration, see the following links https://p6spy.readthedocs.io/en/latest/configandusage.html
demo link
https://github.com/lyb-geek/springboot-learning/tree/master/springboot-p6spy
边栏推荐
- Webrtc native M96 version opening trip -- a reading code download and compilation (Ninja GN depot_tools)
- Pytorch through load_ state_ Dict load weight
- Transferring images using flask
- 1110 complete binary tree (25 points)
- "Hands on deep learning" pytorch edition Chapter II exercise
- Online VR model display - 3D visual display solution
- (subplots用法)matplotlib如何绘制多个子图(轴域)
- Redis 过期淘汰机制
- Brief introduction of realsense d435i imaging principle
- 穀歌 | 蛋白序列的深度嵌入和比對
猜你喜欢
![[Yu Yue education] basic reference materials of interchangeability and measurement technology of Zhongyuan Institute of Technology](/img/f1/d0dc4dc3fe49a2d2cd9e452a0ce31e.jpg)
[Yu Yue education] basic reference materials of interchangeability and measurement technology of Zhongyuan Institute of Technology

Go practice -- gorilla / websocket used by gorilla web Toolkit

appium1.22.x 版本後的 appium inspector 需單獨安裝

Botu uses peek and poke for IO mapping

Yolov5 model construction source code details | CSDN creation punch in
![[batch dos-cmd command - summary and summary] - CMD window setting and operation command - close CMD window and exit CMD environment (exit, exit /b, goto: EOF)](/img/ce/d6f4fb30727e7436b6443537429ad4.png)
[batch dos-cmd command - summary and summary] - CMD window setting and operation command - close CMD window and exit CMD environment (exit, exit /b, goto: EOF)

Training method of grasping angle in grasping detection
![[set theory] relationship properties (common relationship properties | relationship properties examples | relationship operation properties)](/img/af/8dfa783c87363a9d75c52e7680d508.jpg)
[set theory] relationship properties (common relationship properties | relationship properties examples | relationship operation properties)

Appium 1.22. L'Inspecteur appium après la version X doit être installé séparément

XML Configuration File
随机推荐
XML Configuration File
[set theory] relational power operation (relational power operation | examples of relational power operation | properties of relational power operation)
[batch dos-cmd command - summary and summary] - CMD window setting and operation command - close CMD window and exit CMD environment (exit, exit /b, goto: EOF)
Botu uses peek and poke for IO mapping
C language program ideas and several commonly used filters
获取并监控远程服务器日志
1115 counting nodes in a BST (30 points)
1095 cars on campus (30 points)
[practical project] autonomous web server
小学校园IP网络广播-基于校园局域网的小学IP数字广播系统设计
[basic grammar] C language uses for loop to print Pentagram
Bluebridge cup real topic 2020 palindrome date simulation construction provincial competition
(perfect solution) how to set the position of Matplotlib legend freely
Explanation of several points needing attention in final (tested by the author)
6.23星期四库作业
Pan details of deep learning
Go practice - gorilla / handlers used by gorilla web Toolkit
[Yu Yue education] basic reference materials of interchangeability and measurement technology of Zhongyuan Institute of Technology
1103 integer factorization (30 points)
穀歌 | 蛋白序列的深度嵌入和比對