Joinc

导航

dump Java 程序和服务器相关信息

#!/bin/bash

jps -lm

read -p "enter java pid: " pid
port=$(netstat -ntlp | grep $pid | awk '{printf $4}' | cut -d':' -f4)

read -p "pid: ${pid}, http port: ${port}, continue? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1

# pause_url="http://localhost:${port}/actuator/pause\n"
# echo "try pause application from ${pause_url}."
# curl -XPOST $pause_url
# echo ''
# pause_url="http://localhost:${port}/sba/pause\n"
# echo "try pause application from ${pause_url}."
# curl -XPOST $pause_url

dir=$(mktemp -d)
echo "files will save to ${dir}."
cd $dir

echo "try dump server memory info."
free -h > free.dat

echo "try dump server cpu info."
top -c -b -n 1 > top.dat

echo "try dump process thread cpu info."
top -c -b -n 1 -Hp $pid > top_thread.dat

echo "try dump process thread stack info."
jstack $pid > threads.dat

echo "try dump process heap info."
jmap -dump:format=b,file=./heap.hprof $pid
echo "try compress hprof file."
tar zcvf heap.hprof.tar.gz ./heap.hprof

 

posted on 2019-07-04 13:05  Joinc  阅读(294)  评论(0编辑  收藏  举报