淘宝TProfiler可以持续对JVM监控,对线上影响较小。
具体安装使用可以参考 https://wenda.zuncuang.com/article/67
我对源码编译打包后,一直运行有问题,所以从这里直接下载打包好的jar包吧 TProfiler下载
参考配置文件如下,配置文件和jar包在一个目录下:
#basic configuration items
startProfTime = 9:00:00
endProfTime = 11:00:00
eachProfUseTime = 5
eachProfIntervalTime = 50
samplerIntervalTime = 20
port = 50000
debugMode = false
needNanoTime = false
ignoreGetSetMethod = true
#file paths
logFilePath = /logs/tprofiler/log/tprofiler.log
methodFilePath = /logs/tprofiler/log/tmethod.log
samplerFilePath = /logs/tprofiler/log/tsampler.log
#include & excludes items
excludeClassLoader = org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader
includePackageStartsWith = com.meitianhui
excludePackageStartsWith = com.taobao.sketch;org.apache.velocity;com.alibaba;com.taobao.forest.domain.dataobject
1 要进行分析,首先把采集到的数据flush到本地文件,可以在一台远程机器上编写如下脚本 tprofiler.sh:
#!/bin/bash
tprofiler_jar=/root/TProfiler/dist/lib/tt/tprofiler-1.0.1.jar
host='10.45.23.144 10.25.168.172'
port=50000
if [ $# -ne 1 ];then
echo $"Usage: $0 {start|stop|status|flushmethod}"
exit
fi
for ip in $host;do
/webdata/opt/local/jdk1.7.0_09/bin/java -cp $tprofiler_jar com.taobao.profile.client.TProfilerClient $ip $port $1
done
2,运行上面脚本。tpprofiler.sh flushmethod 把采集到方法刷到各个部署机器本地目录,
然后部署机器本地目录编写下面小脚本,stas.sh
#!/bin/bash
log=/logs/tprofiler/log
mkdir -p $log/sample $log/stats
java -cp /logs/tprofiler/tprofiler-1.0.1.jar com.taobao.profile.analysis.ProfilerLogAnalysis tprofiler.log tmethod.log stats/tian_topmethod.log stats/tian_topobject.log
java -cp /logs/tprofiler/tprofiler-1.0.1.jar com.taobao.profile.analysis.SamplerLogAnalysis tsampler.log sample/smethod.log sample/sthread.log
其中 tprofiler.log tmethod.log tsampler.log tpprofiler.sh flushmethod 产生的文件
stats/tian_topmethod.log stats/tian_topobject.log sample/smethod.log sample/sthread.log 为stas.sh 脚本分析出的最终结果