监控
1.操作系统: cpu 内存 swap 磁盘IO 网络IO
vmstat mpstat pidstat
top(linux) prstat(solaris)
2.java进程: cpu 内存 swap 磁盘IO 网络IO
基本信息:命令行 系统属性: 默认系统属性 -D 动态增加的系统属性 flags
类加载信息
线程
内存:heap, 永久代(元空间), 堆外内存(nio 申请的一些内存, 又称原生内存native memory)
gc
=========================================================================
1.基本信息
jcmd xxx VM.uptime
jcmd xxx VM.version
jcmd xxx VM.command_line 命令行
jcmd xxx VM.system_properties (jinfo -sysprops xxx) 系统属性
jcmd xxx VM.flags [-all] (查询的结果中 “:=” 表示的是非默认值; “=” 表示的是默认值 )
jinfo -flags xxx 查看所有flag
jinfo -flag PrintGCDetails xxx 查看单个falg
jinfo -flag [+|-]<PrintGCDeatils> xxx 使能/去使能 某个flag
jinfo -flag <name>=<value> PID 修改某个flag的值
查看所有支持动态修改的flag:
Flags marked as manageable are dynamically writeable through the JDK management interface (com.sun.management.HotSpotDiagnosticMXBean API) and also through JConsole.
jinfo (java configuration info):实时查看和调整jvm配置参数。
=========================================================================
3.线程
jstack [-l] <pid> : -l 选项用来打印锁的相关信息
jcmd xxx Thread.print
4.内存
4.1 堆(heap)
1. 利用 jmap -histo xxxPID jmap -histo:live xxxPID
例如
mainClassName=xxxxx
jps -l |grep -i ${mainClassName} |awk '{print $1}' |xargs jmap -histo |awk 'NR == 1 {print "num" "\t" "instance_num" "\t" "memory" "\t" "class"} NR > 3 && NR<20 {print $1 "\t" $2 "\t" $3/1024/1024 "\t" $4}'
2. 利用 jcmd xxxPID GC.class_histogram
“jcmd xxxPID GC.class_histogram"命令,不会强制执行full GC, 它只显示活跃对象。
"jmap -histo xxxPID" 也不会强制执行full GC, 但它会显示非活跃对象,所以在使用它之前需要用户自己手动执行full GC。
"jmap -histo:live xxxPID" 同 “jcmd xxxPID GC.class_histogram" (会手动触发一次full gc)
3 堆转储
jmap -dump:live,file=/home/abcd/heap_dump_cmall_biz.hprof 27975(pid) (会触发一次full gc)
jmap -dump:file= xxxPid (所有对象都dump出来,不触发full gc)
-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>
jcmd process_id GC.heap_dump /path/to/heap_dump.hprof (会触发full gc吗?可以自测下)
生成的堆转储文件,可以用jhat jvisualVM mat(EclipseLink Memory Analyzer Tool)
4.
jmap -heap 进程ID
4.2 原生内存(native memory)
-XX:NativeMemoryTracking=off|summary|detail
%jcmd process_id VM.native_memory summary
=========================================================================
5.GC
jstat -gcutil process_id 1000(多少毫秒重复执行这个命令)
输出消耗在GC上的时间,以及每个GC区域使用的百分比。