【问题标题】:Real time CPU% by process monitoring script in AIX 6.1AIX 6.1 中进程监控脚本的实时 CPU%
【发布时间】:2017-06-17 20:48:01
【问题描述】:

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

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

ps aux

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

top

在 AIX 系统中不存在。

【问题讨论】:

    标签: bash shell sh cpu-usage aix


    【解决方案1】:

    通过创建一个生成 30 秒 tprof 日志并遍历它们的脚本来解决这个问题,通过 PID 将进程线程相加并达到或多或少等于实时 CPU 负载百分比进程列表的总和。

    【讨论】:

      【解决方案2】:
      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
      
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-07-22
        • 2011-11-04
        • 1970-01-01
        • 2012-02-05
        • 1970-01-01
        • 2015-08-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多