您的位置:首页 > 运维架构 > Linux

监视linux内存和CPU

2012-12-20 14:21 190 查看
#!bin/sh

#the login name

username=see

#the process name

psname=java

timeout=5

pid=`ps -u $username |grep $psname |grep -v grep|grep -v vi|grep -v db|grep -v tail|grep -v start|grep -v stop |sed -n 1p |awk '{print $1}'`

echo "username=$username processname=$psname pid=$pid"

#The process does exist or not

if [ "-$pid" == "-" ]

then

echo "then process does not exit"

fi

while true

do

DATE=`date +%H:%M:%S-%Y-%m-%d`

# CPU value

cpuValue=`ps -p $pid -o pcpu | grep -v CPU | awk '{print $1}' | awk -F. '{print $1}'`

echo "$DATE process used CPU $cpuValue%"

#if [ "$cpuValue" -gt 400 ]

#then

# echo "The usage of cpu is larger than 400%"

#else

# echo "The usage of cpu is normal"

#fi

#physics Memory

MEMUsage=`ps -o rss -p $pid | grep -v RSS`

echo "$DATE RSS is $[$MEMUsage/1024]MB"

#dummy Memory

VSZ=`ps -o vsz -p $pid | grep -v VSZ`

echo "$DATE VSZ is $[$VSZ/1024]MB "

sleep $timeout

done
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: