cpu性能监控
#!/bin/bash column_count=
i=
m=
is_want=
str_msg="";
file_name=./test/`date +%Y-%m-%d`_CPU.txt for p in `ps -eo pcpu,pid |sort -k -rn`
do if [ `expr $i % $column_count` = ]
then
str_msg=""; #if [ `expr $p \> $m` = 1 ] && [ "$p"x != "%CPU"x ]
if [ `awk -v a=$p -v b=$m 'BEGIN{print(a>b)?"a":"b"}'` = 'a' ] && [ "$p"x != "%CPU"x ]
then
str_msg="CPU=$p"; is_want=
else
#is_want=
break
fi
# elif [ `expr $i % $column_count` = ] && [ $is_want = ]
# then
# str_msg=$p;
elif [ `expr $i % $column_count` = ] && [ $is_want = ]
then
str_msg="$str_msg,PID=$p";
#echo $str_msg
echo [`date +%Y-%m-%d_%H:%M:%S`]$str_msg >> $file_name;
fi i=`expr $i + ` #sleep 0.5; done echo [`date +%Y-%m-%d_%H:%M:%S`]"" >> $file_name;
memory性能监控
#!/bin/bash column_count=
i=
m=
is_want=
str_msg="";
file_name=./test/`date +%Y-%m-%d`_memory.txt for p in `ps -eo rss,pid |sort -k -rn`
do if [ `expr $i % $column_count` = ]
then
str_msg=""; #if [ `expr $p \> $m` = 1 ] && [ "$p"x != "%CPU"x ]
if [ `awk -v a=$p -v b=$m 'BEGIN{print(a>b)?"a":"b"}'` = 'a' ] && [ "$p"x != "%CPU"x ]
then
str_msg="memory=$p"; is_want=
else
#is_want=
break
fi
# elif [ `expr $i % $column_count` = ] && [ $is_want = ]
# then
# str_msg=$p;
elif [ `expr $i % $column_count` = ] && [ $is_want = ]
then
str_msg="$str_msg,PID=$p";
#echo $str_msg
echo [`date +%Y-%m-%d_%H:%M:%S`]$str_msg >> $file_name;
fi i=`expr $i + ` #sleep 0.5; done echo [`date +%Y-%m-%d_%H:%M:%S`]"" >> $file_name;