Sun JDK监控和故障处理工具.

一、测试环境

[root@iZ25w1kdi5zZ ~]# cat /etc/redhat-release
CentOS release 6.5 (Final)
[root@iZ25w1kdi5zZ ~]# java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

二、常用工具

1.jps

jsp可以列出正在运行的虚拟机进程,并显示其执行主类(main函数所在的类)的名称和进程ID。
jps的用法:
[root@iZ25w1kdi5zZ ~]# jps -help
usage: jps [-help]
       jps [-q] [-mlvV] [<hostid>]

Definitions:
    <hostid>:      <hostname>[:<port>]
jps命令主要选项:
-q 只输出进程ID的名称,省略主类的名称
-m 输出虚拟机进程启动时传递给主类main()函数的参数
-l 输出主类的命名,如果进程执行的是Jar包,则输出Jar的路径
-v 输出虚拟机进程启动时JVM参数
示例:
[root@iZ25w1kdi5zZ ~]# jps -l
4310 sun.tools.jps.Jps
22336 org.apache.catalina.startup.Bootstrap

2.jstat

jstat是用于监视虚拟机各种运行状态信息的命令行工具。它可以显示本地或远程虚拟机进程中的类装载、内存、垃圾收集、JIT编译等运行状况。在不能使用GUI图形界面的情况下,它将是运行期定位虚拟机问题的首选工具。

jstat用法:

[root@iZ25w1kdi5zZ ~]# jstat -help
Usage: jstat -help|-options
       jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]

Definitions:
  <option>      An option reported by the -options option
  <vmid>        Virtual Machine Identifier. A vmid takes the following form:
                     <lvmid>[@<hostname>[:<port>]]
                Where <lvmid> is the local vm identifier for the target
                Java virtual machine, typically a process id; <hostname> is
                the name of the host running the target Java virtual machine;
                and <port> is the port number for the rmiregistry on the
                target host. See the jvmstat documentation for a more complete
                description of the Virtual Machine Identifier.
  <lines>       Number of samples between header lines.
  <interval>    Sampling interval. The following forms are allowed:
                    <n>["ms"|"s"]
                Where <n> is an integer and the suffix specifies the units as 
                milliseconds("ms") or seconds("s"). The default units are "ms".
  <count>       Number of samples to take before terminating.
  -J<flag>      Pass <flag> directly to the runtime system.
jstat命令主要选项:
-class            监视类装载、卸载数量、总空间及类装载所耗费的时间
-gc               监视Java堆状况,包括Eden区、2个survivor区、老年代、永久代等的容量、已用空间、GC时间等时间
-gccapacity       监视内容与-gc相同,输出主要关注Java堆各个区域使用的最大空间和最小空间
-gcutil           监视内容与-gc基本相同,输出主要关注已使用空间占总空间的百分比
-gccause          与-gcutil功能一样,但会额外输出导致上一次GC产生的原因
-gcnew            监视新生代GC的状况
-gcnewcapacity    监视内容与-gcnew基本相同,输出主要关注使用到的最大空间和最小空间
-gcold            监视老年代GC的状况
-gcoldcapacity    监视内容与-gcold基本相同,输出主要关注使用的最大空间和最小空间
-gcpermcapacity   输出永久代使用的最大空间和最小空间
-compiler         输出JIT编译器编译过的方法、耗时等信息
-printcompilation 输出已经被JIT编译的方法

示例:

[root@iZ25w1kdi5zZ ~]# jstat -gcutil 22336
  S0     S1     E      O      P     YGC     YGCT    FGC    FGCT     GCT   
  0.00  20.31  87.14  76.26  44.72   1475    4.316     2    0.329    4.645

3.jinfo

jinfo命令的作用就是实时地查看和调整虚拟机的各项参数。jinfo可以使用-sysprops选项把虚拟机进程的System.getProperties()的内容打印出来,并且还可以通过-flag选项查询未被显示指定的参数的系统默认值,jps -v只能查看虚拟机启动时显式指定的参数列表。同时,jinfo命令还能够在运行期修改JVM参数,可以使用-flag[+|-]name或-flag name=value来修改一部分运行期可写的虚拟机参数值。

jinfo用法:

[root@iZ25w1kdi5zZ ~]# jinfo -help
Usage:
    jinfo [option] <pid>
        (to connect to running process)
    jinfo [option] <executable <core>
        (to connect to a core file)
    jinfo [option] [server_id@]<remote server IP or hostname>
        (to connect to remote debug server)

where <option> is one of:
    -flag <name>         to print the value of the named VM flag
    -flag [+|-]<name>    to enable or disable the named VM flag
    -flag <name>=<value> to set the named VM flag to the given value
    -flags               to print VM flags
    -sysprops            to print Java system properties
    <no option>          to print both of the above
    -h | -help           to print this help message
示例:

[root@iZ25w1kdi5zZ ~]# jinfo -flag SurvivorRatio 22336
-XX:SurvivorRatio=8

4.jstack


5.jmap

6.btrace


7.JConsole


8.VisualVM



猜你喜欢

转载自blog.csdn.net/god_wot/article/details/50445168