8.2 Common Commands
8.2.1 jps
View java process jps -l
8.2.2 jinfo
Real-time view and adjust JVM arguments
1) Check the name attribute of a java process
jinfo -flag MaxHeapSize PID
jinfo -flag UseG1GC PID
2) modify the parameters
Only marked as manageable the flag can be modified in real time
jinfo -flag [+|-] PID
jinfo -flag = PID
3) Check out some of the parameters have been assigned
jinfo -flags PID
8.2.3 jstat
1) Check VM performance statistics
2) See class loading information
查看某个java 进程的类装载信息,每1000毫秒输出一次,共输出10次
jstat -class PID 1000 10
3) Check the garbage collection information
jstat -gc PID 1000 10
8.2.4 jstack
View thread stack information
jstack PID
8.2.5 jmap
Health heap dump snapshot
1) print out the heap memory information
-XX:PrintFlagsFinal -Xms300M -Xmx300M
jmap -heap PID
2) dump the heap memory information
jmap -dump:format=b,file=heap.hprof PID
3) Set heap memory overflow, automatic dump file
-XX:HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=heap.hprof
8.3 Common tools
8.3.1 jconsole
JConsole is JDK that comes with visual monitoring tool.
命令行输入:jconsole
8.3.2 jvisualvm
Monitoring can be local, remote java process CPU, class, thread
(1) Select the "Remote" in visualvm, right-click the "Add"
(2) the server's ip address written on a host name, such as 31.100.39.63, then click "OK"
(3) Right-click the host "31.100.39.63", adding "JMX" [that is, through JMX technology to monitor a remote server which specific Java process]
In the startup items plus the following parameters:
-Dcom.sun.management.jmxremote - Djava.rmi.server.hostname=31.100.39.63 -Dcom.sun.management.jmxremote.port=8998 -Dcom.sun.management.jmxremote.ssl=false - Dcom.sun.management.jmxremote.authenticate=true - Dcom.sun.management.jmxremote.access.file=../conf/jmxremote.access - Dcom.sun.management.jmxremote.password.file=../conf/jmxremote.password"
Create two files
jmxremote.access
guest readonly
manager readwrite
jmxremote.password
guest guest
manager manager
Grant permission: chmod 600 jmxremot
8.3.3 Arthas
Arthas is a diagnostic tool Alibaba Java open source, using the command line interactive mode,
Official website: https: //github.com/alibaba/arthas
8.3.3.1 download and install
curl -O https://alibaba.github.io/arthas/arthas-boot.jar
java -jar arthas-boot.jar
# 然后可以选择一个Java进程
Print usage
java -jar arthas-boot.jar -h
8.3.3.2 commonly used commands
version:查看arthas版本号
help:查看命名帮助信息
cls:清空屏幕
session:查看当前会话信息
quit:退出arthas客户端
---
dashboard:当前进程的实时数据面板
thread:当前JVM的线程堆栈信息
jvm:查看当前JVM的信息
sysprop:查看JVM的系统属性
---
sc:查看JVM已经加载的类信息
dump:dump已经加载类的byte code到特定目录
jad:反编译指定已加载类的源码
---
monitor:方法执行监控
watch:方法执行数据观测
trace:方法内部调用路径,并输出方法路径上的每个节点上耗时
stack:输出当前方法被调用的调用路径
......
8.3.4 MAT
java heap analyzer for finding memory leaks
Download: https://www.eclipse.org/mat/downloads.php
8.3.5 GC log analysis tool
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamps
-XX:+PrintGCDateStamps
-Xloggc:gc.log
Online
- http://gceasy.io
GCViewer
When I let go of what I am , I become what I might be.
Out of the comfort zone, meet better themselves.