MyPerf4J 采用 JavaAgent 配置方式,透明化接入应用,对应用代码彻底没有侵入。java
项目地址:
https://github.com/LinShunKang/MyPerf4J
git项目到本地:git
git clone git@github.com:LinShunKang/MyPerf4J.git
打包项目:github
mvn clean package
在 JVM 启动参数里加上如下两个参数jvm
-javaagent:D:/workspqce/MyPerf4J/MyPerf4J-ASM-2.5.0.jar -DMyPerf4JPropFile=D:/workspqce/MyPerf4J/myPerf4J.properties
其中,myPerf4J.properties
的配置以下:日志
# 应用名称 AppName=MyPerf4JTest # MetricsProcessor类型,0:以标准格式化结构输出到stdout.log 1:以标准格式化结构输出到磁盘 2:以InfluxDB LineProtocol格式输出到磁盘 MetricsProcessorType=1 # 配置各个Metrics日志的文件路径,可不配置 MethodMetricsFile=d:/data/logs/MyPerf4J/method_metrics.log ClassMetricsFile=d:/data/logs/MyPerf4J/class_metrics.log GCMetricsFile=d:/data/logs/MyPerf4J/gc_metrics.log MemMetricsFile=d:/data/logs/MyPerf4J/memory_metrics.log BufPoolMetricsFile=d:/data/logs/MyPerf4J/buf_pool_metrics ThreadMetricsFile=d:/data/logs/MyPerf4J/thread_metrics.log # 配置Record模式,可配置为accurate/rough RecorderMode=accurate # 配置时间片,单位为ms,最小1s,最大600s MilliTimeSlice=10000 # 须要监控的package,可配置多个,用英文';'分隔 #IncludePackages=com.chinasofti.huateng.lz.qrcode.server.controller; IncludePackages=com.mmzsit.controller; # 不须要监控的package,可配置多个,用英文';'分隔 # ExcludePackages=com.chinasofti.huateng.lz.qrcode.server.config; # 默认监控IncludePackages下的全部方法 # 不监控的方法:可配置多个方法名,用英文';'分隔 ExcludeMethods=upload # 是否展现方法参数类型 ShowMethodParams=true # 是否排除私有方法,true/false ExcludePrivateMethod=true # 通用的方法执行时间阈值,单位为ms ProfilingTimeThreshold=1000 # 在一个时间片内,超过方法执行时间阈值的次数,仅在RecorderMode=accurate时有效 ProfilingOutThresholdCount=10
2019-03-27 18:25:25.234 [MyPerf4J] WARN profilingParamFile is empty! 2019-03-27 18:25:25.330 [MyPerf4J] INFO __ ___ ____ ______ __ __ / |/ /_ __/ __ \___ _____/ __/ // / / / / /|_/ / / / / /_/ / _ \/ ___/ /_/ // /___ / / / / / / /_/ / ____/ __/ / / __/__ __/ /_/ / /_/ /_/\__, /_/ \___/_/ /_/ /_/ \____/ /____/ 2019-03-27 18:25:25.331 [MyPerf4J] INFO AbstractBootstrap doInitial() SUCCESS!!!
启动时出现的提示信息:WARN profilingParamFile is empty!能够不用理会,由于不影响使用。code
输出结果,输出到d:/data/logs/MyPerf4J/method_metrics.log
server
MyPerf4J Method Metrics [2019-03-27 18:24:20, 2019-03-27 18:24:30] Method[1] Type RPS Avg(ms) Min(ms) Max(ms) StdDev Count TP50 TP90 TP95 TP99 TP999 TP9999 TP99999 TP100 FtpController.download() General 0 540.00 540 540 0.00 1 540 540 540 540 540 540 540 540 MyPerf4J Method Metrics [2019-03-27 18:24:30, 2019-03-27 18:24:40] Method[1] Type RPS Avg(ms) Min(ms) Max(ms) StdDev Count TP50 TP90 TP95 TP99 TP999 TP9999 TP99999 TP100 FtpController.upload() General 0 467.00 467 467 0.00 1 467 467 467 467 467 467 467 467