The script that prints the Java thread occupancy stack is invoked if the CPU occupancy rate continues to reach more than 80, see https://github.com/oldratlee/useful-shells/blob/master/ Show-busy-java-threads.sh, see his GitHub wiki! in concrete usage
#!/bin/bash #cpu Idle percent cpu_idle= ' top-b-D 1-n 2 | grep Cpu | awk ' Nr>1{print $} ' | Cut-f 1-d "." ' If [-d '/opt/scripts/log '] then cd/opt/scripts else mkdir/opt/scripts/log fi count=0 condition=true while Co Ndition do if [$cpu _idle-le] then pids= ' Top-b-d 1-n 1 | grep java |
awk ' {if ($ >) print} ' for ((a = 1; a < a++) does 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 to PID in $pids Do date= ' date +%y%m%d%h%m ' jmap-heap $pid > Log/heap_$pid_$date.log done count++ cpu_i Dle= ' Top-b-D 1-n 2 | grep Cpu | awk ' Nr>1{print $} ' | 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
The above mentioned is the entire content which this article shares, hoped everybody can like.