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

Real time CPU% by process monitoring script in AIX 6.1

我正在尝试编写一个脚本来按进程 (PID) 实时监控 AIX 6.1 服务器中的 CPU% 负载,并且一直在 IBM 文档和整个 Whosebug 中搜索此内容。

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

ps aux

不用说,这不是我需要的,因为它只监控进程在会话时间内使用了多少 CPU%,在我的情况下,会话时间相当长。 我需要的信息包含在 topas 和 nmon 中,但我不知道如何为每个单独时刻抓取此信息的快照。

top

在 AIX 系统中不存在。

通过制作一个生成 30 秒 tprof 日志并遍历它们的脚本解决了这个问题,通过 PID 添加进程线程并达到或多或少等于 real-time CPU load% 进程列表。

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

function fetch_UARG_process_by_pid () 
{

#Check_Argument  

#parameter initialization 
filesource=
cpuvalue=
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  , }' | 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 }'
             echo -e "And the long desciption of the process:" 
                         grep UARG  | grep $processid | awk -F "," '{print }'
             echo -e "\n"
             fi
        done
  done

}