由于应用内存过高会导致应用异常,所以特写当前的脚本验证。而内存过高可能由以前的原因导致:
#!/bin/bash
cd `dirname $0`
hostname=$(hostname)
ip=$(/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|grep -E "10|192" |awk '{print $2}')
processName=$2
thredhold=$3
PIDS=`ps -ef | grep "$processName" | grep -v grep | awk '{print $2}'`
if [ -n "$PIDS" ]; then
for PID in $PIDS; do
MEM=`top -n 1 -c | grep ${PID} | awk '{print $6 }'`
MEM=${MEM%?}
MEM=$(printf "%.0f" ${MEM})
thredhold=$(printf "%.0f" ${thredhold})
echo "${PID}=${MEM}"
if [[ ${MEM} -gt ${thredhold} ]]; then
# 发送告警信息
fi
done
fi