JDK built-in tools use
- jps (Java Virtual Machine Process Status Tool)
View all jvm processes, including process ID, process startup path, etc. - jstack (Java Stack Trace)
① Observe the running status of all threads in the jvm and the current state of the threads.
② System crashed? If the java program crashes to generate the core file, the jstack tool can be used to obtain the information of the java stack and native stack of the core file, so that you can easily know how the java program crashes and where the problem occurs in the program.
③ Is the system hung? The jstack tool can also be attached to the running java program to see the information of the java stack and the native stack of the running java program at that time. If the current running java program is in a hung state, jstack is very useful. - jstat (Java Virtual Machine Statistics Monitoring Tool)
① jstat uses the built-in instructions of the JVM to monitor the resources and performance of Java applications in real-time on the command line, including the classloader, compiler, and gc of the process;
② monitor VM memory The various heap and non-heap sizes and their memory usage, as well as the number of loaded classes. - jmap (Java Memory Map)
monitors the occupancy of the physical memory of the jvm in the running process, and the situation of all objects in the process memory, such as which objects are generated and the number of objects; - jinfo (Java Configuration Info)
observes process running environment parameters, including Java System properties and JVM command-line parameters
Use specific commands:
- jstat
generalOption
-help Displays help information. -version Displays version information -options Displays a list of statistics options.
#Parameters : - class: Statistical class loader behavior -compiler: Statistical HotSpot Just - in - Time compiler behavior - gc: Counting the usage of each partition of the heap - gccapacity: Counting the heap of the new area, the old area, and the permanent area Capacity situation - gccause: Count the reasons for the last GC and current GC - gcnew: Count GC, the situation of the new generation - gcnewcapacity: Count the size and space of the new generation - gcold: Count the behavior of the old and permanent generation - gcoldcapacity: Count the old Age size - gcpermcapacity: Statistics permanent generation size - gcutil: When statistics gc, heap situation - printcompilation: HotSpot compilation method statistics
#Monitor every 1 second, a total of 10 times jstat -class 17970 1000 10 ########################################## [root@lq225 conf]# jstat -class 2058 1000 10 Loaded Bytes Unloaded Bytes Time 1697 3349.5 0 0.0 1.79 1697 3349.5 0 0.0 1.79 1697 3349.5 0 0.0 1.79 1697 3349.5 0 0.0 1.79 ................................................... # ###################### Term Separator ####################### # # Loaded number of classes loaded # Bytes loaded size (k) # Unloaded number of classes unloaded # Bytes unloaded size (k) # Time spent performing class loading and unloading operations
Compiled Failed Invalid Time FailedType FailedMethod 302 0 0 1.27 0 ..................................................... # ###################### Term Separator ####################### # # Compiled The number of executions of the compilation task # Failed The number of failed compilation tasks # Invalid The number of times the compilation task was invalid # Time The time spent on the compilation task # FailedType The type of the last compilation error # FailedMethod The class name and method of the last compilation error
#Monitor every 2 seconds, a total of 20 times jstat -gc 2058 2000 20 ############################# S0C S1C S0U S1U EC EU OC OR PC PU YGC YGCT FGC FGCT GCT 8704.0 8704.0 805.5 0.0 69952.0 64174.5 174784.0 2644.5 16384.0 10426.7 2 0.034 0 0.000 0.034 8704.0 8704.0 805.5 0.0 69952.0 64174.5 174784.0 2644.5 16384.0 10426.7 2 0.034 0 0.000 0.034 8704.0 8704.0 805.5 0.0 69952.0 64174.5 174784.0 2644.5 16384.0 10426.7 2 0.034 0 0.000 0.034 ............................................. # ###################### Term Separator ####################### # # S0C Survivor Area 0 Capacity (KB) # S1C Survivor Area 1 Capacity (KB) # S0U Survivor Area 0 Usage (KB) # S1U Survivor Area 1 Usage (KB) # EC Eden Area Capacity (KB ) ) # EU Eden area usage (KB) # OC old area capacity (KB) # OU old area usage (KB) # PC permanent area capacity (KB) # PU permanent area usage (KB) # YGC new generation GC times # YGCT young generation GC time # FGC full GC event times # FGCT full GC time # GCT total GC time
NGCMN NGCMX NGC S0C S1C EC OGCMN OGCMX OGC OC PGCMN PGCMX PGC PC YGC FGC 131072.0 131072.0 131072.0 13056.0 13056.0 104960.0 393216.0 393216.0 393216.0 393216.0 65536.0 65536.0 65536.0. .......................................................................................................... # ###################### Term Separator ####################### # # NGCMN Minimum Young Generation Capacity (KB) # NGCMX Maximum Young Generation Capacity (KB) # NGC Current Young Generation Capacity (KB) # S0C Current Survivor Zone 0 Capacity (KB) # S1C Current Survivor Zone 1 Capacity (KB) # OGCMN Old age minimum size (KB) # OGCMX Old age maximum size (KB) # OGC current old age capacity (KB). # OC Current old age? Current old space capacity (KB). # PGCMN permanent area minimum capacity (KB) # PGCMX permanent area maximum capacity (KB) # PGC current permanent area capacity (KB). # PC Current permanent area? Current Permanent space capacity (KB). # The number of YGC young GC events # The number of FGC Full GC events
S0 S1 E O P YGC YGCT FGC FGCT GCT LGCC GCC 0.00 99.84 12.76 0.92 46.23 1 0.016 0 0.000 0.016 unknown GCCause No GC ................................................ # ###################### Term Separator ####################### # # The percentage of the current capacity used by the first survivor (survivor area) in the young generation of S0 # The percentage of the current capacity used by the second survivor (survivor area) in the young generation of S1 # Eden (the Garden of Eden) in the young generation Used percentage of current capacity # O Old generation used percentage of current capacity # P Perm generation used percentage of current capacity # YGC The number of gcs in the young generation from application startup to sampling # FGC From application startup to Sampling time old generation (full gc) gc times # FGCT time from application startup to sampling time old generation (full gc) gc (s) # GCT total time from application startup to sampling time gc (s) # LGCC Reason for last GC # GCC Reason for current GC
#Monitor every 1 second, a total of 10 times jstat -gcutil 2058 1000 10 ################################ [root@lq225 conf]# jstat -gcutil 2058 1000 10 S0 S1 E O P YGC YGCT FGC FGCT GCT 9.25 0.00 96.73 1.51 63.64 2 0.034 0 0.000 0.034 9.25 0.00 96.73 1.51 63.64 2 0.034 0 0.000 0.034 9.25 0.00 96.73 1.51 63.64 2 0.034 0 0.000 0.034 9.25 0.00 96.73 1.51 63.64 2 0.034 0 0.000 0.034
- jmap
# Parameter -dump:[live,]format=b,file=<filename> Use hprof binary form, output the heap content of jvm to file = . The live sub-option is optional, if the live option is specified, only the live ones are output Object to file. - finalizerinfo prints information about objects waiting to be reclaimed. - heap prints heap summary information, algorithms used by GC, heap configuration and wise heap usage. -histo[:live] prints an instance of each class Number, memory usage, full class name information. The VM's internal class name will be prefixed with "* ". If the live subparameter is added, only the number of live objects will be counted. - permstat prints classload and jvm heap persistent layer information . Contains each classloader's name, liveness, address, parent classloader and the number of classes loaded. In addition, the number of internal Strings and the number of memory occupied will also be printed. -F forced. Use -dump or when pid does not correspond - histo parameter. In this mode, the live sub-parameter is invalid. -h | - help print auxiliary information - J pass parameters to the jvm started by jmap. pid is the java process id whose matching information needs to be printed.
jmap -histo 2058 ############################ num #instances #bytes class name ---------------------------------------------- 1: 206 3585312 [I 2: 19621 2791880 <constMethodKlass> 3: 19621 2520048 <methodKlass> 4: 21010 2251616 [C ............................................................
#The generated files can be analyzed using the jhat tool, which is very useful to analyze large objects during OOM (memory overflow). jmap -dump:live,format=b,file=data.hprof 2058 #You can also get the dump file by starting the JVM with the following parameters: -XX:+ HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=./java_pid<pid> .hprof #If the heap information file exported in the virtual machine can be analyzed on WINDOWS, you can find problems such as memory, you can do this: jhat data.hprof #After successful execution, visit http://localhost:7000 View memory information. (open port 7000 first)
- jinfo
#View the configuration information of the java process jinfo 2058 ##################### Attaching to process ID 2058, please wait... Debugger attached successfully. Server compiler detected. JVM version is 24.0-b56 Java System Properties: java.runtime.name = Java(TM) SE Runtime Environment project.name = Amoeba-MySQL java.vm.version = 24.0-b56 sun.boot.library.path = /usr/local/java/jdk1.7/jre/lib/amd64 ................................................ #View the MaxPerm size of 2058 can be used jinfo -flag MaxPermSize 2058 ############################ -XX:MaxPermSize=100663296
- jps
#List all java processes in the system jps # ######################## 2306 Bootstrap 3370 Jps 2058 xxxxxxxxx
SOC: The capacity (bytes) of the first survivor (survivor area) in the young generation S1C: The capacity of the second survivor (survivor area) in the young generation (bytes) S0U: The currently used space (bytes) of the first survivor (survivor area) in the young generation S1U: The currently used space (bytes) of the second survivor (survivor area) in the young generation EC: The capacity of Eden (Garden of Eden) in the young generation (bytes) EU: Eden (Eden) in the young generation currently used space (bytes) OC: capacity of the Old generation (bytes) OU: Old generation currently used space (bytes) PC: Perm (Persistent Generation) capacity (bytes) PU: Perm (persistent generation) currently used space (bytes) YGC: The number of gc in the young generation from application startup to sampling time YGCT: The time (s) used by gc in the young generation from the application startup to the sampling time FGC: The number of GCs in the old generation (full GC) from application startup to sampling time FGCT: The time (s) from the application startup to the old generation (full gc) gc of the sampling era GCT: The total time (s) used by gc from application startup to sampling NGCMN: Initialized (minimum) size (bytes) in young generation (young) NGCMX: The maximum capacity (bytes) of the young generation (young) NGC: The current capacity (bytes) in the young generation (young) OGCMN: initialized (minimum) size (bytes) in old generation OGCMX: the maximum capacity of the old generation (bytes) OGC: the current newly generated capacity of the old generation (bytes) PGCMN: initialized (minimum) size (bytes) in perm generation PGCMX: Maximum capacity of perm generation (bytes) PGC: The current newly generated capacity of the perm generation (bytes) S0: The percentage of the current capacity used by the first survivor (survivor area) in the young generation S1: The percentage of the current capacity used by the second survivor (survivor area) in the young generation E: The percentage of the current capacity used by Eden (Eden) in the young generation O: The percentage of the current capacity used by the old generation P: The percentage of the current capacity used by the perm generation S0CMX: The maximum capacity (bytes) of the first survivor (survivor area) in the young generation S1CMX: The maximum capacity (bytes) of the second survivor (survivor area) in the young generation ECMX: The maximum capacity of Eden (Eden) in the young generation (bytes) DSS: The capacity (bytes) of the survivor (survivor area) currently required (the Eden area is full) TT: Hold count limit MTT: Maximum number of holdings
Monitor tomcat with visualvm
- Modify catalina.sh and add the following line:
CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote=true -Djava.rmi.server.hostname=192.168.55.255 -Dcom.sun.management.jmxremote.port=8086 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false" #Note : # 1. Use hostname -i to check whether it is 127.0.01. If so, you must configure -Djava.rmi.server.hostname as the local IP. # 2. Check whether the firewall (iptables) is enabled, and whether the port specified by jmxremote.port is open.