CPU usage monitoring in AIX servers

37,302

You can list the top 5 in a fairly readable way by limiting the columns, sorting them with the highest CPU usage first, and then truncating to the first 5 (using head -6, since we also want to include the headers):

ps -eo pcpu,pid,args | sort -k 1 -r | head -6

The output looks something like this:

%CPU   PID COMMAND
 2.0 30531 -bash
 0.0 30673 head -6
 0.0 30672 sort -k 1 -r
 0.0 30671 ps -eo pcpu,pid,args
 0.0 30670 [flush-253:0]

You might also want to look into GNU top's batch mode (-b).

Share:
37,302

Related videos on Youtube

debal
Author by

debal

Updated on September 18, 2022

Comments

  • debal
    debal almost 2 years

    In order to monitor the CPU usage in an AIX server I'm using the following script that is executed every 10 mins.

    lparstat 2 10 > cpu
    usage=$(tail -10 cpu | awk 'BEGIN {sum=0;} {sum+=$4} END{print int(100-sum/10)}')
    
    
    if [[ $usage -ge 90 ]]; then
    # mail the error and cpu file to admin
    # displaying this for testing purposes
    echo "CPU usage off the charts!!!"
    cat cpu
    fi
    

    However, in case the CPU usage is above 90% I need to list the top 5 Processes that are using the CPU.

    How do I achieve this?

  • debal
    debal over 10 years
    Unfortunately in the AIX system that I'm uing top is unavailable and has topas. ps -eo pcpu,pid,args | sort -rk1 | head -6 does give the output, but the result doesn't match with the result of topas.
  • clerksx
    clerksx over 10 years
    @debal Why must the result match topas?
  • debal
    debal over 10 years
    both these commands tend to do the same thing, wouldn't it be surprising if the two results don't match? topas is giving a realtime view of the CPU usage, ps -eo pcpu,pid,args | sort -rk1 | head -6 is giving for a particular point of time, so at that instance it only makes sense if both these commands provide the same result. Which is not the case.
  • covener
    covener about 7 years
    That's not exactly the contrast point -- ps gives you a weird process lifetime vs. CPU seconds which is not necessarily indicative of what's causing high CPU "recently". topas, like top, gives you the % over a much short reasonable that is intuitively usually what people want.