欢迎来到我的博客小站。  交流请加我微信好友: studyjava。  也欢迎关注公众号:Java学习之道 Fork me on GitHub

整合 MyPerf4J 做Java性能监控和统计工具

快速启动MyPerf4J

MyPerf4J 采用 JavaAgent 配置方式,透明化接入应用,对应用代码完全没有侵入。

打包

项目地址:
https://github.com/LinShunKang/MyPerf4J

git项目到本地:

git clone git@github.com:LinShunKang/MyPerf4J.git

打包项目:

mvn clean package

配置

在 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!可以不用理会,因为不影响使用。

运行

输出结果,输出到d:/data/logs/MyPerf4J/method_metrics.log

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


posted @ 2019-03-28 15:29  淼淼之森  阅读(1054)  评论(0编辑  收藏  举报
  👉转载请注明出处和署名