JVM 监控 - jps jstack jmap top jhat

  1. jps 查看 java 进程信息
  2. jstack 可查看java进程里的存活线程状态
  3. jmap 可查看java进程堆内存使用情况
  4. top linux 命令,可查看java某进程的线程
  5. jhat 可查看dump文件
  • jps  
    • jps 简单列出java进程 
[root@localhost app]# jps
5666 WatchdogServer
5746 XmlAppTransporterContext
5683 Bootstrap
10515 Jps
11929 XmlAppTransporterContext
11915 WatchdogServer

 

  • jstack 
    • jstack [pid] -> jstack 5666 列出指定进程下的线程情况
    • jstack [pid] | grep '关键字' -> jstack 5666 | grep 'RUNNABLE' 同上带有过滤
[root@localhost app]# jstack 5666
2019-04-04 16:10:28
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.181-b13 mixed mode):

"Attach Listener" #30 daemon prio=9 os_prio=0 tid=0x00007f7998002800 nid=0x6bf7 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"pool-4-thread-1" #29 prio=5 os_prio=0 tid=0x00007f798c04b000 nid=0x1664 waiting on condition [0x00007f79bd8d0000]
   java.lang.Thread.State: WAITING (parking)
        at sun.misc.Unsafe.park(Native Method)
        - parking to wait for  <0x00000000ca803bf8> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
        at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
        at java.util.concurrent.ArrayBlockingQueue.take(ArrayBlockingQueue.java:403)
        at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

"JMX client heartbeat 3" #28 daemon prio=5 os_prio=0 tid=0x00007f798c041800 nid=0x1663 waiting on condition [0x00007f79bd9d1000]
   java.lang.Thread.State: TIMED_WAITING (sleeping)
        at java.lang.Thread.sleep(Native Method)
        at com.sun.jmx.remote.internal.ClientCommunicatorAdmin$Checker.run(ClientCommunicatorAdmin.java:175)
        at java.lang.Thread.run(Thread.java:748)

"RMI RenewClean-[127.0.0.1:37134]" #27 daemon prio=5 os_prio=0 tid=0x00007f798c03f800 nid=0x165f in Object.wait() [0x00007f79bdad2000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144)
        - locked <0x00000000ca7faaf0> (a java.lang.ref.ReferenceQueue$Lock)
        at sun.rmi.transport.DGCClient$EndpointEntry$RenewCleanThread.run(DGCClient.java:563)
        at java.lang.Thread.run(Thread.java:748)

"input-stream-pool-1" #26 prio=5 os_prio=0 tid=0x00007f798c015800 nid=0x165b waiting on condition [0x00007f79bddde000]
   java.lang.Thread.State: WAITING (parking)
        at sun.misc.Unsafe.park(Native Method)
        - parking to wait for  <0x00000000ca7b5548> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
        at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
        at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
        at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

"input-stream-pool-0" #25 prio=5 os_prio=0 tid=0x00007f798c014000 nid=0x165a runnable [0x00007f79bdedf000]
   java.lang.Thread.State: RUNNABLE
        at java.io.FileInputStream.readBytes(Native Method)
        at java.io.FileInputStream.read(FileInputStream.java:255)
        at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
        at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
        at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
        - locked <0x00000000ca7c26c8> (a java.lang.UNIXProcess$ProcessPipeInputStream)
        at com.creditease.ns4.gear.watchdog.monitor.process.WatchdogChildProcess.readInputStream(WatchdogChildProcess.java:85)
        at com.creditease.ns4.gear.watchdog.monitor.process.WatchdogChildProcess.access$000(WatchdogChildProcess.java:38)
        at com.creditease.ns4.gear.watchdog.monitor.process.WatchdogChildProcess$1.run(WatchdogChildProcess.java:127)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

"DestroyJavaVM" #24 prio=5 os_prio=0 tid=0x00007f79dc00b000 nid=0x1623 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

 

  • jmap 
    • jmap -heap [pid] -> jmap -heap 5666 列出指定进程的堆内存使用情况
[root@localhost app]# jmap -heap 5666
Attaching to process ID 5666, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.181-b13

using parallel threads in the new generation.
using thread-local object allocation.
Concurrent Mark-Sweep GC

Heap Configuration:
   MinHeapFreeRatio         = 40
   MaxHeapFreeRatio         = 70
   MaxHeapSize              = 1073741824 (1024.0MB)
   NewSize                  = 174456832 (166.375MB)
   MaxNewSize               = 174456832 (166.375MB)
   OldSize                  = 899284992 (857.625MB)
   NewRatio                 = 2
   SurvivorRatio            = 8
   MetaspaceSize            = 21807104 (20.796875MB)
   CompressedClassSpaceSize = 1073741824 (1024.0MB)
   MaxMetaspaceSize         = 17592186044415 MB
   G1HeapRegionSize         = 0 (0.0MB)

Heap Usage:
New Generation (Eden + 1 Survivor Space):
   capacity = 157024256 (149.75MB)
   used     = 9306376 (8.875251770019531MB)
   free     = 147717880 (140.87474822998047MB)
   5.926712367291841% used
Eden Space:
   capacity = 139591680 (133.125MB)
   used     = 9306376 (8.875251770019531MB)
   free     = 130285304 (124.24974822998047MB)
   6.666855789686033% used
From Space:
   capacity = 17432576 (16.625MB)
   used     = 0 (0.0MB)
   free     = 17432576 (16.625MB)
   0.0% used
To Space:
   capacity = 17432576 (16.625MB)
   used     = 0 (0.0MB)
   free     = 17432576 (16.625MB)
   0.0% used
concurrent mark-sweep generation:
   capacity = 899284992 (857.625MB)
   used     = 2130744 (2.0320358276367188MB)
   free     = 897154248 (855.5929641723633MB)
   0.2369375691749563% used

4999 interned Strings occupying 395840 bytes.
  • jmap -histo[:live] [pid] -> jmap -histo:live 5666 关键字live列出存活对象
 num     #instances         #bytes  class name
----------------------------------------------
   1:          8633         556016  [C
   2:          2168         245408  java.lang.Class
   3:          8621         206904  java.lang.String
   4:           544         188632  [B
   5:          1896         101440  [Ljava.lang.Object;
   6:           551          48488  java.lang.reflect.Method
   7:           873          48064  [I
   8:          1382          44224  java.util.HashMap$Node
   9:          1303          41696  java.util.concurrent.ConcurrentHashMap$Node
  10:           203          23200  [Ljava.util.HashMap$Node;
  11:          1143          18288  java.lang.Object
  12:           390          15600  java.lang.ref.SoftReference
  13:           429          14880  [Ljava.lang.String;
  14:            41          14704  [Ljava.util.concurrent.ConcurrentHashMap$Node;
  15:           395          12640  java.util.Hashtable$Entry
  16:           221          12376  java.lang.invoke.MemberName
  17:           480          11608  [Ljava.lang.Class;
  18:           239          11472  java.util.HashMap
  19:           341          10912  sun.misc.FDBigInteger
  20:            24           9024  java.lang.Thread
  21:           219           8760  java.util.LinkedHashMap$Entry
  22:           291           6984  java.lang.Long
  23:           206           6592  java.lang.invoke.LambdaForm$Name
  24:            74           6528  [Ljava.util.WeakHashMap$Entry;
  25:           102           6528  java.net.URL
  26:           158           6320  java.lang.invoke.MethodType
  27:            96           5760  [Ljava.lang.ref.SoftReference;
  28:            71           5680  java.lang.reflect.Constructor
  29:           229           5496  javax.management.ImmutableDescriptor
  30:            50           5448  [Ljava.util.Hashtable$Entry;
  31:           167           5344  java.lang.invoke.MethodType$ConcurrentWeakInternSet$WeakEntry
  32:           166           5312  com.sun.jmx.mbeanserver.ConvertingMethod
  33:           126           5040  java.util.WeakHashMap$Entry
  34:           279           4464  java.lang.Integer
  35:            67           4288  javax.management.openmbean.OpenMBeanAttributeInfoSupport
  36:           256           4096  java.lang.Byte
  37:           256           4096  java.lang.Short
  38:           102           4080  java.lang.ref.Finalizer
  39:           123           3936  java.lang.ref.WeakReference
  40:            92           3680  java.util.TreeMap$Entry
  41:            71           3408  java.util.WeakHashMap
  42:            71           3408  java.util.logging.LogManager$LoggerWeakRef
  43:            68           3264  java.lang.invoke.LambdaForm
  44:            73           3248  [Ljava.lang.invoke.LambdaForm$Name;
  45:           173           3144  [Lcom.sun.jmx.mbeanserver.MXBeanMapping;
  46:            94           3008  java.lang.ref.ReferenceQueue
  47:            54           2968  [Ljavax.management.MBeanAttributeInfo;
  • class name 列说明
B  byte 
C  char 
D  double 
F  float 
I  int 
J  long 
Z  boolean 
[  数组,如[I表示int[] [L+类名 其他对象
  • jmap -dump:format=b,file=[filename] [pid] -> jmap -dump:format=b,file=./dump.dat 5666 给指定进程生成dump
  • jhat -port 9999 ./dump.dat 查看生成的dump,浏览器打开:http://localhost:9999

JVM 监控 - jps jstack jmap top jhat_第1张图片

上面图片是引用其他文章-Other Queries 最后一项支持OQL(对象查询语言)

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