当前位置:网站首页>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
边栏推荐
- leetcode406. Rebuild the queue based on height
- Objects. Requirenonnull method description
- Yolov5 input (II) | CSDN creative punch in
- DEX net 2.0 for crawl detection
- Configure and use Anaconda environment in pycharm
- Go practice -- use redis in golang (redis and go redis / redis)
- 1095 cars on campus (30 points)
- Botu uses peek and poke for IO mapping
- Go practice -- gorilla/rpc (gorilla/rpc/json) used by gorilla web Toolkit
- Make your own dataset
猜你喜欢

穀歌 | 蛋白序列的深度嵌入和比對

【实战项目】自主web服务器

Webrtc M96 release notes (SDP abolishes Plan B and supports opus red redundant coding)

appium1.22.x 版本後的 appium inspector 需單獨安裝
![[basic grammar] C language uses for loop to print Pentagram](/img/9e/021c6c0e748e0981d4233f74c83e76.jpg)
[basic grammar] C language uses for loop to print Pentagram

Principles of BTC cryptography

Intégration profonde et alignement des séquences de protéines Google

6.23星期四库作业

appium1.22.x 版本后的 appium inspector 需单独安装

Brief introduction of realsense d435i imaging principle
随机推荐
Detailed explanation of yolov5 training own data set
JS dynamic table creation
请求数据库报错:“could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGram
1095 cars on campus (30 points)
1118 birds in forest (25 points)
Covering Safari and edge, almost all mainstream browsers have realized webgl 2.0 support
appium1.22.x 版本後的 appium inspector 需單獨安裝
Messy change of mouse style in win system
appium1.22. Appium inspector after X version needs to be installed separately
"250000 a year is just the price of cabbage" has become a thing of the past. The annual salary of AI posts has decreased by 8.9%, and the latest salary report has been released
Gbase8s composite index (I)
[practical project] autonomous web server
XML Configuration File
Unity tool Luban learning notes 1
动态规划——相关概念,(数塔问题)
2022-02-11 daily clock in: problem fine brush
[set theory] relational power operation (relational power operation | examples of relational power operation | properties of relational power operation)
Win10 install pytullet and test
[basic grammar] C language uses for loop to print Pentagram
Introduction to deep learning - definition Introduction (I)