性能监控与故障处理工具


性能监控与故障处理工具

介绍处理jvm的相关问题办法以及相关工具的一个持续更新的集合

📚 经验

CPU占用率高

  • 通过jvm工具排查
  1. 通过top命令查询进程号
  2. 通过top -Hp 查到线程号,转换成为16进制
  3. 通过jstack |grep 16进制线程号 -A 10 找到CPU当前执行的方法堆栈
  • 通过arthas排查
  1. thread

# 查看线程状态(默认只显示10个线程)
thread 

# 查看全部线程状态
thread --all

# 查看指定线程执行状态
thread --pid

OOM问题

  1. 启动命令中设置

-XX:+HeapDumpOnOutOfMemoryError 配合 -XX:HeapDumpPath
在OOM时生成dump文件

  1. 线上命令
#生成堆转储快照dump文件命令
  jmap -dump:format=b,file=heapdump.hprof pid
# 生成堆栈信息文件命令
  jstack -l pid >> stack.txt
# Arthas命令
  heapdump

线程问题

  • 线程池提交任务不执行

# arthas排查

# 获取ClassLoad Hash
sc -d com.agmtopy.source.executer.ExecutorServiceUtil

# 获取对象
ognl -x 1 '@com.agmtopy.source.executer.ExecutorServiceUtil@threadPoolExecutor'
  • 线程死锁

 # arthas排查
Thread -b

⚙ 工具

Arthas强烈推荐

📒 常用命令

网络

# 采样tcp连接
lsof -p 进程号 > /tmp/进程号_lsof.txt
# 查看指定端口
netstat -tnlp | grep :8080
ss -tunlp |grep :8080

排查网络问题步骤:

  1. ping 目标地址
  2. 丢包
    a. 链路中断
    b. 抖动
    c. 出口堵塞
  3. 能通
    a. 检查dns和域名解析

/etc/resolv.conf 或者 dig 或者 nslookup :url

b. 检查端口

telnet -> 如果全部端口不通检查安全组策略;部分端口不通检查负载均衡白名单

  1. 不通
    检查ip设置/网卡驱动/物理链路

内存


# 系统内存分布
pmap -pid

# 内存占用
jmap -heap 进程号 > /tmp/进程号_jmap_heap.txt

# 保存进程堆栈
jmap -dump:format=b,file=/tmp/进程号_jmap_dump.hprof 进程号

# 内存对象占比
jmap -histo 1 |more

# GC
jstat -gcutil 进程号 > /tmp/进程号_jstat_gc.txt

jstat -gcutil 1 1s

CPU


# 查看系统上下文切换
vmstat -w 1

# 查看进程上下文切换
pidstat -p /PID -wtu  5

# 打印系统负载快照
top -b -n 2 > /tmp/top.txt
top -H -n 1 -p pid > /tmp/pid_top.txt

# 进程列表
ps -mp-o THREAD,tid,time | sort -k2r > /tmp/进程号_threads.txt

# 线程信息
jstack -l 进程号 > /tmp/进程号_jstack.txt

# Arthas
thread 
thread -tid
thread -all

I/O

strace -p pid
iotop

  TOC