Linux shell腳本實(shí)現(xiàn)CPU預(yù)警
如果CPU占用率持續(xù)達(dá)到80以上則調(diào)用打印java線程占用率堆棧的腳本,見https://github.com/oldratlee/useful-shells/blob/master/show-busy-java-threads.sh,具體用法見他的github wiki!
#!/bin/bash #cpu idle percent cpu_idle=`top -b -d 1 -n 2 | grep Cpu | awk 'NR>1{print $5}' | cut -f 1 -d "."` if [ -d "/opt/scripts/log" ] then cd /opt/scripts else mkdir /opt/scripts/log fi count=0 condition=true while condition do if [ $cpu_idle -le 20 ] then pids=`top -b -d 1 -n 1 | grep java | awk '{if($9 > 80) print $1}'` for ((a = 1; a < 10; a++)) do for pid in $pids doi #involve jdk existence check later date=`date +%Y%m%d%H%M` sh showstack.sh -c 30 -p $pid > log/stack_$pid_$date.log jstat -gcutil $pid > log/gc_$pid_$date.log done done for pid in $pids do date=`date +%Y%m%d%H%M` jmap -heap $pid > log/heap_$pid_$date.log done count++ cpu_idle=`top -b -d 1 -n 2 | grep Cpu | awk 'NR>1{print $5}' | cut -f 1 -d "."` if [ $count -ge 3] then #send emaili #server ip address ip=`ifconfig eth0 | grep "inet addr" | cut -f 2 -d ":" | cut -f 1 -d " "` condition=false count=0 fi else condition=false count=0 fi done
以上所述就是本文給大家分享的全部?jī)?nèi)容了,希望大家能夠喜歡。
- linux查看cpu是否支持64位的方法
- linux php-cgi.exe占用cpu 100%的一次排障之旅
- Linux中使用Shell腳本查看Java線程的CPU使用情況
- linux vps服務(wù)器進(jìn)程kswapd0與events/0消耗大量CPU的問題
- linux使用管道命令執(zhí)行ps獲取cpu與內(nèi)存占用率
- linux系統(tǒng)使用python獲取cpu信息腳本分享
- 使用python獲取CPU和內(nèi)存信息的思路與實(shí)現(xiàn)(linux系統(tǒng))
- Linux2.6對(duì)新型CPU的支持
- Linux 查看cpu 信息的命令及簡(jiǎn)單實(shí)例
相關(guān)文章
簡(jiǎn)介L(zhǎng)inux中cp和mv搭配{,}在shell當(dāng)中的用法
這篇文章主要介紹了簡(jiǎn)介L(zhǎng)inux中cp和mv搭配{,}在shell當(dāng)中的用法,作者舉了四個(gè)這樣的大括號(hào)擴(kuò)展示例,需要的朋友可以參考下2015-06-06linux shell命令行選項(xiàng)與參數(shù)用法詳解
本文介紹了linux shell中使用命令行選項(xiàng)與命令行參數(shù)的方法,在bash中,可以用以下三種方式來(lái)處理命令行參數(shù),每種方式都有自己的應(yīng)用場(chǎng)景2014-04-04Linux 使用grep篩選多個(gè)條件及grep常用過濾命令
這篇文章主要介紹了Linux 使用grep篩選多個(gè)條件及grep常用過濾命令,需要的朋友可以參考下2018-07-07shell腳本實(shí)現(xiàn)分日志級(jí)別輸出的方法
下面小編就為大家?guī)?lái)一篇shell腳本實(shí)現(xiàn)分日志級(jí)別輸出的方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧2017-03-03