JVM信息查询命令

1、查询jar包运行进程

jps   #通过jps命令找出jar的进程ID

JVM信息查询命令_第1张图片

ps -ef|grep xxxx    #通过包名找出进程ID

2、查询JVM的堆信息

jmap -heap  pid  #通过jmap命令查询堆信息
root@d57bff9f-c8nvn:/apps# jmap -heap 6
Picked up JAVA_TOOL_OPTIONS:  -Xloggc:/data/tsf_apm/monitor/jvm-metrics/gclog.log 
Picked up _JAVA_OPTIONS: -XX:+UseContainerSupport  -XX:MinRAMPercentage=50.0  -XX:MaxRAMPercentage=50.0   -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m
Attaching to process ID 6, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.322-b06

using thread-local object allocation.
Parallel GC with 4 thread(s)

Heap Configuration: #堆的内存配置信息
   MinHeapFreeRatio         = 0    #最小堆内存缩容比例, -XX:MinHeapFreeRatio=
   MaxHeapFreeRatio         = 100  #最大堆内存使用比例, -XX:MaxHeapFreeRatio=
   MaxHeapSize              = 4294967296 (4096.0MB) #最大堆内存
   NewSize                  = 44564480 (42.5MB)     #当前新生代堆内存
   MaxNewSize               = 1431306240 (1365.0MB) #最大新生代堆内存
   OldSize                  = 89653248 (85.5MB) #当前老年代堆内存
   NewRatio                 = 2  #新生代/老年代内存比例: 1:2
   SurvivorRatio            = 8  #幸存者/eden比例: 1:8
   MetaspaceSize            = 134217728 (128.0MB) #当前元空间内存(方法区)
   CompressedClassSpaceSize = 528482304 (504.0MB)
   MaxMetaspaceSize         = 536870912 (512.0MB) #最大元空间内存(方法区)
   G1HeapRegionSize         = 0 (0.0MB) #G1堆区域大小

Heap Usage: #堆的使用情况
PS Young Generation #年轻代
Eden Space: 
   capacity = 563609600 (537.5MB)  #分配的Eden内存
   used     = 380015152 (362.4106903076172MB) #已使用的Eden内存
   free     = 183594448 (175.0893096923828MB) #剩余的Eden内存
   67.42524470839389% used
From Space: 
   capacity = 37748736 (36.0MB) 
   used     = 37745880 (35.997276306152344MB)
   free     = 2856 (0.00272369384765625MB)
   99.99243418375652% used
To Space:
   capacity = 40370176 (38.5MB)
   used     = 0 (0.0MB)
   free     = 40370176 (38.5MB)
   0.0% used
PS Old Generation #老年代
   capacity = 327155712 (312.0MB)
   used     = 235106360 (224.21489715576172MB)
   free     = 92049352 (87.78510284423828MB)
   71.86374908838516% used

66556 interned Strings occupying 7261200 bytes.

注: 当堆中新生代Eden和from的堆内存满了,就会触发GC;
当老年代堆内存满了则触发full GC,这是会STW(stop the world)暂停JVM的所有线程,导致访问停滞,优化JVM其实就是为了防止STW.

3、jstat -gc pid
说明:jstat命令查询JVM的堆内存及GC的统计 。

root@d57bff9f-c8nvn:/apps# jstat  -gc 6
Picked up JAVA_TOOL_OPTIONS:  -Xloggc:/data/tsf_apm/monitor/jvm-metrics/gclog.log 
Picked up _JAVA_OPTIONS: -XX:+UseContainerSupport  -XX:MinRAMPercentage=50.0  -XX:MaxRAMPercentage=50.0   -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m
 S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT   
44544.0 43008.0  0.0   38287.8 649728.0 596945.7  319488.0   229988.1  145792.0 133340.3 17792.0 15920.2    213   10.250   4      1.249   11.499
root@d57bff9f-c8nvn:/apps#

命令:jstat -gcutil pid

jstat -gcutil   6   

在这里插入图片描述
注:如需监听gc的持续情况,则在后面加上时间(单位毫秒)
如:jstat -gcutil pid 1000 或 jstat -gc pid 1000
JVM信息查询命令_第2张图片

4、查询JVM运行中线程信息

jstack -l  pid   #通过jstack命令

在thread dump中,要留意下面几种状态
死锁:Deadlock(重点关注)
等待资源:Waiting on condition(重点关注)
等待获取监视器,Waiting on monitor entry(重点关注)
阻塞,Blocked(重点关注)
• 执行中:Runnable
• 暂停:Suspended
• 对象等待中:Object.wait() 或 TIMED_WAITING
• 停止:Parked

你可能感兴趣的:(jvm,java,linux)