监视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
#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
相关文章推荐
- linux 下取进程占用 cpu/内存 最高的前10个进程
- Linux下如何查看CPU型号、个数、核数、逻辑CPU数、位数、发行版本、内核信息、内存、服务器生产厂家
- linux查看内存、cpu等硬件信息
- Linux查看CPU和内存使用情况(转)
- Linux查看硬件信息,主板型号及内存硬件,驱动设备,查看设备,查看CPU。
- linux查看内存cpu占用
- Linux查看CPU和内存的配置信息
- Linux查看CPU和内存使用情况
- Linux查看CPU和内存使用情况
- 用jconsole来监视远程服务器的内存,cpu状况
- Linux查看CPU和内存使用情况(转载)
- Linux查看CPU和内存使用情况
- linux下查看CPU、内存、磁盘信息
- 获取linux系统的各服务进程与CPU、内存、硬盘空间使用状态
- Linux 查看CPU,内存,硬盘
- Linux查看CPU和内存使用情况
- Linux下查看CPU、内存和硬盘信息命令
- Linux查看CPU和内存使用情况
- Linux 查看CPU,内存,硬盘
- Linux查看CPU型号及内存频率及其它信息的命令