先总结下常用的一些监控工具:
linux命令
w系统负载
lsof -p pid进程打开的文件
lsof -i:port端口的运行情况
free -m内存情况
vmstat进程、内存、内存分页、堵塞IO、traps及CPU活动的信息
iostat磁盘io情况
top -n 1cpu/负载/内存等使用情况.
iotop磁盘io
ps aux | sort -k6nr | head -n 10查看linux 实际内存占用最多的10个
ps aux | sort -k5nr | head -n 10查看linux 虚拟内存占用最多的10个
dstat -lamps查看系统整体状况
pstree -al pid|head -n 1查看进程启动命令
strace -T -p pid查看进程系统调用.开销很大,使用时要小心.
netstatnetstat -an |grep port查看端口连接情况netstat -alnp |grep pid通过pid查看进程所有端口情况ss -lntp |grep port通过端口查看进程
nmon强大的监控工具.也可以方便的出报表.我一般用来在压力测试时监控系统性能.
latencytop用于查看系统内部慢.以前做mysql性能优化,多亏有这东东.
cat /proc/pid/status |grep Threads查看进程内线程个数
java工具
jvisualvmjvm的运行情况/各种dump的分析都可以干,没有JRMC牛.oracle承诺会把JRockit的特性迁移到HotSpot上面来.现在jdk下已经有jmc了.
jps -lv查看所有java进程.
jinfo -sysprops pid查看java进程系统参数
jinfo -flag jvmflag pid查看jvm flag.比如查看xss,
jinfo -flag ThreadStackSize pidjstack pid查看线程栈信息
jmap -dump:live,format=b,file=xxx.hprof pid生成heap dump
jmap -histo pid查看java堆中对象统计信息
java -XX:+UnlockDiagnosticVMOptions -XX:+PrintFlagsFinal查看jvm flag
The first column appears to reflect the data type of the option (intx, uintx, uint64_t, bool, double, ccstr, ccstrlist). The second column is the name of the flag and the third column is the value, if any, that the flag is set to. The fourth column appears to indicate the type of flag and has values such as {product},{pd product}, {C1 product} for client or {C2 product} for server, {C1 pd product} for client or {C2 pd product} for server, {product rw}, {diagnostic} (only if -XX:+UnlockDiagnosticVMOptions was specified), {experimental}, and {manageable}. See Eugene Kuleshov's The most complete list of -XX options for Java 6 JVM for a brief description of most of these categories as well as a listing of most of these options themselves.-
线程栈分析器,这个是jvisualvm的插件.
-
基于eclipse的heap dump分析工具,这个工具是比jvisualvm在heap分析这块专业.不过jvisualvm能cover住大多数场景,基本上我都只用jvisualvm了.
jmap -heap pid检查heap情况
-
GC日志分析
jstat -gcutil pid查看gc总体情况
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 — 从应用程序启动到采样时用于垃圾回收的总时间(单位秒)btrace神器,线上出问题了,想知道某个方法的调用情况,入参之类的,就靠btrace了.
此工具大致原理如下:btrace-clientattach 目标进程(com.sun.tools.attach.VirtualMachine#attach)- 加载agent
btrace-agent(com.sun.tools.attach.VirtualMachine#loadAgent) - agent启动服务端,开启监听端口
brace-client把编译好的用户btrace代码发送到服务端,并等待服务端响应btrace-agent通过asm修改运行时代码,织入用户btrace代码逻辑.监控到信息后,发给btrace-client
jmc
生成记录
#检查特性是否开启 jcmd 23385 VM.check_commercial_features #开启商业特性 jcmd 23385 VM.unlock_commercial_features #检查JFR状态 jcmd 23385 JFR.check #执行180sJFR收集 jcmd 23385 JFR.start name=recording filename=/root/recording.jfr duration=180svjtools
https://github.com/vipshop/vjtools 主要工具vjtop非常有用,打印JVM概况及繁忙线程