JvmTop監控JVM的TOP命令

banq發表於2013-09-03
JvmTop.java - jvmtop是一款類似Linux下TOP的Java監控命令,可以時刻查詢JVM內部執行緒執行情況,和Jstack一起配合使用,能夠發現導致系統負載增大的一些原因。

jvmtop.sh -h 可以獲得幫助.
jvmtop.sh JVM的PID 能夠獲得這個JVM內部的執行緒情況。
JVM的PID可以透過PS命令獲得。

舉例監控sh命令:
#!/bin/sh
PID=`ps aux | sort -rnk 3 | awk '{print $2}' |head -n 1`
/home/jdon/jvmtop.sh -n3 $PID >>out.txt

如果JVM成為最忙碌的,列印出該JVM內部執行緒,遍歷三次,如下:

PID 24188: com.jvmtop.JvmTop 
 ARGS: 1801
 VMARGS: 
 VM: Sun Microsystems Inc. Java HotSpot(TM) Client VM 1.6.0_31
 UP:  0: 3m  THR: 12   THRPEAK: 12   THRCREATED: 12   USER: root        
 GC-Time:  0: 0m   GC-Runs: 67        TotalLoadedClasses: 1475    
 CPU:  2.78% GC:  0.00% HEAP:   5m / 245m NONHEAP:  18m / 118m

  TID   NAME                                    STATE    CPU  TOTALCPU BLOCKEDBY
     14 RMI TCP Connection(1)-10.241.8       RUNNABLE  0.93%     0.77%       
      1 main                            TIMED_WAITING  0.93%    86.63%       
     15 JMX server connection timeout   TIMED_WAITING  0.00%     0.00%       
     13 RMI TCP Accept-0                     RUNNABLE  0.00%     0.00%       
     12 Attach Listener                      RUNNABLE  0.00%     0.51%       
     11 Thread-1                        TIMED_WAITING  0.00%     0.00%       
     10 RMI Scheduler(0)                TIMED_WAITING  0.00%     0.00%       
      9 GC Daemon                       TIMED_WAITING  0.00%     0.00%       
      8 RMI RenewClean-[110.76.43.83:3  TIMED_WAITING  0.00%     0.00%       
      4 Signal Dispatcher                    RUNNABLE  0.00%     0.00%       
 Note: Only top 10 threads (according cpu load) are shown!
<p class="indent">







相關文章