AIX 6.1中的进程监视脚本的实时CPU%

时间:2017-02-01 07:25:03

标签: bash shell sh cpu-usage aix

我试图编写一个脚本,通过进程(PID)监视AIX 6.1服务器中的实时CPU%负载,并且一直在IBM文档和整个堆栈溢出中搜索这个。

我只找到人们使用的例子,例如

ps aux

毋庸置疑,这不是我所需要的,因为它只监视进程在会话时间内使用了多少CPU%,在我的情况下这是很长的。  我需要的信息包含在topas和nmon中,但我不知道如何为每个时刻获取此信息的快照。

top

在AIX系统中不存在。

2 个答案:

答案 0 :(得分:0)

解决这个问题,方法是创建一个生成30秒tprof日志的脚本,并通过它们迭代它们,按PID累加进程线程,并得到一个等于或多或少等于实时CPU负载%进程列表的总和。

答案 1 :(得分:0)

Here is a function I use to search and grab CPU load from nmon data log 

function fetch_UARG_process_by_pid () 
{

#Check_Argument $1 $2

#parameter initialization 
filesource=$1
cpuvalue=$2
readarray -t X <<< "$(grep TOP $filesource)"
length=${#X[@]}

#echo " this is the length of my array : $length"
#you have to start from 2 to avoid the first lines that describe the content of the file
#TOP,%CPU Utilisation
#TOP,+PID,Time,%CPU,%Usr, Sys,Size,ResSet,ResText,ResData,ShdLib,MinorFault,MajorFault,Command

  for ((i = 2; i != length; i++)); do
    echo ${X[i]} | awk -F "," '{print $2 , $4}' | while read processid n 
        do
                     if (( $(echo "$n > $cpuvalue " |bc -l) )); 
                     then 
             echo    "the value of CPU usage is: $n"
             echo    "the Linux PID is : $processid "
             echo    "And the short desciption of the process:" 
             echo ${X[i]} | awk -F "," '{print $14}'
             echo -e "And the long desciption of the process:" 
                         grep UARG $1 | grep $processid | awk -F "," '{print $5}'
             echo -e "\n"
             fi
        done
  done

}
相关问题