内存常用脚本
1、统计每个进程占用内存情况(单位KB)
rm eve_mem.txt ps -eo pid,args > pri_pid.txt while read line do test_PID=`echo ${line}| awk '{print $1}'` test_NAME=`echo ${line}| awk '{print $1=null,$0}'` mem_VmRSS=`cat /proc/${test_PID}/status | grep VmRSS` >/dev/null 2>&1 mem_VmHWM=`cat /proc/${test_PID}/status | grep VmHWM` >/dev/null 2>&1 echo ${test_PID} ${mem_VmHWM} ${mem_VmRSS} ${test_NAME} | grep VmHWM | column -t >> eve_mem.txt done < pri_pid.txt
2、计算所有内存占用总和
all_VmHWM_MEM=0 all_VmRSS_MEM=0 while read line do test_VmHWM_MEM=`echo ${line}| grep VmHWM | awk '{print $3}'` test_VmRSS_MEM=`echo ${line}| grep VmRSS | awk '{print $6}'` all_VmHWM_MEM=`echo $(($all_VmHWM_MEM+$test_VmHWM_MEM))` all_VmRSS_MEM=`echo $(($all_VmRSS_MEM+$test_VmRSS_MEM))` done < eve_mem.txt echo "max: ${all_VmHWM_MEM} use:${all_VmRSS_MEM}"
3、统计大于1G、大于500M、大于100M 的进程列表
echo "500M > pid_mem >= 100M" while read line do test_VmRSS_MEM=`echo ${line}| grep VmRSS | awk '{print $6}'` #echo ${test_VmRSS_MEM} if [[ ${test_VmRSS_MEM} -ge 102400 && ${test_VmRSS_MEM} -lt 512000 ]]; then echo ${line} fi done < eve_mem.txt echo "1G > pid_mem >= 500M" while read line do test_VmRSS_MEM=`echo ${line}| grep VmRSS | awk '{print $6}'` #echo ${test_VmRSS_MEM} if [[ ${test_VmRSS_MEM} -ge 512000 && ${test_VmRSS_MEM} -lt 1024000 ]]; then echo ${line} fi done < eve_mem.txt echo "pid_mem >= 1G" while read line do test_VmRSS_MEM=`echo ${line}| grep VmRSS | awk '{print $6}'` #echo ${test_VmRSS_MEM} if [ ${test_VmRSS_MEM} -ge 1024000 ]; then echo ${line} fi done < eve_mem.txt