2.虚拟机性能监控和故障处理

  • jps:虚拟机进程状况工具

jps [-q] [-mlvV] [<hostid>]
Definitions:
<hostid>: <hostname>[:<port>]

选项 作用
-q 只输出LVMD(进程的虚拟机唯一ID)
-m 输出虚拟机启动时传递给main()函数的参数
-l 输出主类的全名,如果进程执行的是jar包,就输出Jar的路劲
-v 输出虚拟机启动时的JVM参数
  • jstat: 虚拟机统计信息监视工具(非常重要)

Options — 选项,我们一般使用 -gcutil 查看gc情况
vmid — VM的进程号,即当前运行的java进程号
interval– 间隔时间,单位为秒或者毫秒
count — 打印次数,如果缺省则打印无数次

S0 — Heap上的 Survivor space 0 区已使用空间的百分比
S1 — Heap上的 Survivor space 1 区已使用空间的百分比
E — Heap上的 Eden space 区已使用空间的百分比
O — Heap上的 Old space 区已使用空间的百分比
P — Perm space 区已使用空间的百分比
YGC — 从应用程序启动到采样时发生 Young GC 的次数
YGCT– 从应用程序启动到采样时 Young GC 所用的时间(单位秒)
FGC — 从应用程序启动到采样时发生 Full GC 的次数
FGCT– 从应用程序启动到采样时 Full GC 所用的时间(单位秒)
GCT — 从应用程序启动到采样时用于垃圾回收的总时间(单位秒)

选项Option代表用户希望查询的虚拟机信息,主要分为3类:类装载垃圾收集运行期编译状况
jstat工具主要选项:

选项 作用
-class 监视类装载,卸载数量,总空间以及所消耗的时间
-gc 监视Java堆状况,包括Eden区,两个survivor,老年代,永久代的容量,已用空间,GC时间合计等信息。
-gccapacity 监视内容与-gc基本相同,只是输出主要关注于Java堆中使用的最大空间,最小空间。
-gcutil 监视内容和-gc基本相同,只是输出更加关注于已使用空间的百分比
-gccause 监视内容于-gcutil基本相同,但是会额外输出上一次gc产生的原因。
-gcnew 监视新生代的状况
-gcold 监视老年代的状况
-gcnewcapacity 监视内容基本与-gcnew差不多,输出主要关注于使用到的最大最小空间。
-gcoldcapacity 监视内容基本和-gcold相同,输出主要关注于使用到的最大最小空间。
-gcpermcapacity 监视永久代的最大最小空间
-compiler 输出JIT编译器编译过的方法,耗时等信息。
-printcompilation 输出已经被JIT编译过的方法。
  • jinfo: Java配置信息工具
    提供了实时查看和调整虚拟机各项参数
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


  • jmap: Java内存映像工具
    jmap一般是用来生成堆转储快照的,当然也并不只这点功能就是。
Usage:
    jmap [option] <pid>
        (to connect to running process)
    jmap [option] <executable <core>
        (to connect to a core file)
    jmap [option] [server_id@]<remote server IP or hostname>
        (to connect to remote debug server)

where <option> is one of:
    <none>               to print same info as Solaris pmap
    -heap                to print java heap summary
    -histo[:live]        to print histogram of java object heap; if the "live"
                         suboption is specified, only count live objects
    -clstats             to print class loader statistics
    -finalizerinfo       to print information on objects awaiting finalization
    -dump:<dump-options> to dump java heap in hprof binary format
                         dump-options:
                           live         dump only live objects; if not specified,
                                        all objects in the heap are dumped.
                           format=b     binary format
                           file=<file>  dump heap to <file>
                         Example: jmap -dump:live,format=b,file=heap.bin <pid>
    -F                   force. Use with -dump:<dump-options> <pid> or -histo
                         to force a heap dump or histogram when <pid> does not
                         respond. The "live" suboption is not supported
                         in this mode.
    -h | -help           to print this help message
    -J<flag>             to pass <flag> directly to the runtime system

  • jhat: 虚拟机堆转储快照分析工具
    jhat 转储文件

  • jstack: java堆栈跟踪工具

Usage:
    jstack [-l] <pid>
        (to connect to running process)
    jstack -F [-m] [-l] <pid>
        (to connect to a hung process)
    jstack [-m] [-l] <executable> <core>
        (to connect to a core file)
    jstack [-m] [-l] [server_id@]<remote server IP or hostname>
        (to connect to a remote debug server)

Options:
    -F  to force a thread dump. Use when jstack <pid> does not respond (process is hung)
    -m  to print both java and native frames (mixed mode)
    -l  long listing. Prints additional information about locks
    -h or -help to print this help message

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容