Last active
June 18, 2019 06:39
-
-
Save oldratlee/7413404 to your computer and use it in GitHub Desktop.
对内存使用超过10%进程,执行内存dump和pstack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PROG=`basename $0` | |
timestamp=`date "+%Y%m%d_%H%M%S"` | |
TMP=/tmp/${PROG}_${timestamp} | |
ge() { | |
[ $(echo "$1 >= $2" | bc) == 1 ] | |
} | |
dumpMemBiter() { | |
thresholdPercent="$1" | |
while read threadLine ; do | |
pid=`echo ${threadLine} | awk '{print $1}'` | |
pmem=`echo ${threadLine} | awk '{print $3}'` | |
ge "$pmem" "$thresholdPercent" && { | |
echo dumping $pid | |
mkdir -p $TMP | |
cat /proc/${pid}/maps > $TMP/$pid.maps | |
pstack $pid > $TMP/$pid.pstack | |
} | |
done | |
} | |
ps -eo pid,user,pmem,comm --no-header | awk '$4=="httpd"{print $0}' | sort -k3,3 -nr | dumpMemBiter 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment