這篇文章主要介紹如何實現生產服務器CPU飆升到300%排查腳本,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
# author: laizhiyuan
# creator: 2019-08-19
# desc: Timely access to the most CPU-consuming thread information
#!/bin/bash
out_dir=/root/jstacks
test ! -d $out_dir && mkdir -p $out_dir || rm -rf $out_dir/*
doExec() {
# 獲取使用最多CPU的進程id
pid=`top -bn1 | grep "java" | sed -n 1p | awk '{print $1}'`
echo "find use cpu high java pid: $pid"
out_file=$out_dir/$pid
test ! -f $out_file && touch $out_file
# 根據使用最多CPU的進程id獲取使用最多的線程id
tid=`top -bn1 -Hp $pid | sed -n 8p | awk '{print $1}'`
echo "find use cpu high java thread id: $tid"
# 轉換為十六進制
hex_tid=`printf "%x \n" $tid`
echo "to hex tid: $hex_tid"
# jstack出來報錯到文件,方便后面線程調用棧以及內存和對象分析
echo "=====================$(date +%Y-%m-%d_%H:%M:%S)=============================" >> $out_file
jstack $pid | grep $hex_tid -A 20 >> $out_file
}
# 不斷收集,可以通過Ctrl + C 終止
while [ 1 ]
do
doExec
sleep 3s
done
以上是“如何實現生產服務器CPU飆升到300%排查腳本”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。