AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.


#Power
#Power
 View Only
  • 1.  Script to get periodic CPU utilzation of AIX system

    Posted Wed November 12, 2008 05:41 PM

    Originally posted by: smashyrahul


    I want to write the shell script to get CPU utilzation of AIX system, for which I want to setup the cron so that I can get the cpu utilization of the AIX system periodically in a particular file.. thx in Advance.

    Regards,

    Rahul
    #AIX-Forum


  • 2.  Re: Script to get periodic CPU utilzation of AIX system

    Posted Thu November 13, 2008 07:11 AM

    Originally posted by: MarkTaylor


    I would stronlgy suggst using nmon in batch mode and something like nmon2rrd or pgraph rather than re-inventing the wheel .. google for it .. its pretty good ..

    HTH
    Mark Taylor
    #AIX-Forum


  • 3.  Re: Script to get periodic CPU utilzation of AIX system

    Posted Mon November 17, 2008 12:14 AM

    Originally posted by: SystemAdmin


    Hi,

    We use nmon as well, but the following could give you some ideas.

    Regards,
    Spook
    
    #!/usr/bin/ksh ############################################################################### #  collect_perf   Collects performance data 
    
    for SAS system over 60 seconds.   # #                                                                             # #  Collects vmstat and iostat data 
    
    for 60 seconds and builds a log.           # #                                                                             # #  Field  1  Date in yyyymmdd format                                          # #         2  Time in HH:MM format                                             # #         3  Number of CPU units                                              # #         4  MB of memory                                                     # #         5  vmstat  kthr r      Kernel threads in run queue                  # #         6          kthr b      Kernel threads in wait queue                 # #         7          memory avm  Active virtual pages                         # #         8          memory fre  Size of the free list                        # #         9          page re     Pager input/output list                      # #        10          page pi     Pages in per second                          # #        11          page po     Pages out per second                         # #        12          page fr     Pages freed per second                       # #        13          page sr     Pages scanned per second                     # #        14          page cy     Clock cycles used per sec                    # #        15          faults in   Device interrupts per second                 # #        16          faults sy   System calls per second                      # #        17          faults cs   Kernel thread context switches per sec       # #        18          cpu us      User cpu usage as %                          # #        19          cpu sy      System cpu usage as %                        # #        20          cpu id      Cpu idle as %                                # #        21          cpu wa      Cpu wait I/O as %                            # #        22          cpu pc      Number of shared processors consumed         # # 23          cpu ec      Percentage of capacity consumed              # #        24  constant 
    "u"                                                     # #        25  users on system from uptime                                      # #        26  constant 
    "t"                                                     # #        27  iostat  tin        Characters read from ttys                     # #        28          tout       Characters written to ttys                    # #        29  constant 
    "i"                                                     # #        30  iostat  hdisk0 KB read (over 60 seconds)                         # #        31               1                                                   # #        32               2                                                   # #        33               3                                                   # #        34               4                                                   # #        35               5                                                   # #        36               6                                                   # #        37               7                                                   # #        38               8                                                   # #        39               9                                                   # #        40  constant 
    "o"                                                     # #        41  iostat  hdisk0 Kb written                                        # #        42               1                                                   # #        43               2                                                   # #        44               3                                                   # #        45               4                                                   # #        46               5 # #        47               6                                                   # #        48               7                                                   # #        49               8                                                   # #        50               9                                                   # #                                                                             # ###############################################################################   # Initialization # -------------- item[1]=
    "vmstat 60 1" item[2]=
    "iostat 60 1" item[3]=
    "uptime" temp[1]=/tmp/vmstat.$$ temp[2]=/tmp/iostat.$$ temp[3]=/tmp/uptime.$$ date=$(date +
    "%Y%m%d") time=$(date +
    "%H:%M") ds=$(date +
    "%Y_%m")   logFile=/techsupp/log/perf$
    {ds
    }.log   # Run each of the collection programs # ----------------------------------- let i=1 
    
    while (( i <= $
    {#item[*]
    } )) 
    
    do ($
    {item[$i]
    } > $
    {temp[$i]
    } 2>&1)& let i+=1 done   # Wait until the collection jobs have completed # --------------------------------------------- 
    
    while [[ -n 
    "$(jobs)" ]] 
    
    do sleep 5 done   # Format the vmstat data 
    
    for the log # ---------------------------------- sysLine=
    "$(awk /^System/ ${temp[1]})" cpuFld=$
    {sysLine#*lcpu=
    } cpu=$
    {cpuFld%%\ *
    } memFld=$
    {sysLine#*mem=
    } mem=$
    {memFld%MB*
    } dataLine=
    "$(awk '/^[ 0-9][ 0-9\.]+$/ { 
    
    for (i=1;i<=NF;i++) printf(
    "%s|",$(i)) print 
    ""
    }
    ' ${temp[1]})"   # Format the iostat data 
    
    for the log # ---------------------------------- ttyLine=
    "$(awk '/^ *[ 0-9\.]+$/' ${temp[2]})" set -A t $ttyLine diskLine=
    "$(awk '/^hdisk/ { hdiskNum=0+substr($1,6) i[hdiskNum]=$5 o[hdiskNum]=$6 
    } END 
    {printf(
    "i|") 
    
    for (j=0;j<=9;j++) printf(
    "%s|",i[j]) printf(
    "o|") 
    
    for (j=0;j<=9;j++) printf(
    "%s|",o[j]) print 
    ""
    }
    ' ${temp[2]})"   # Format the uptime data 
    
    for the log # ---------------------------------- ttyLine=
    "$(cat ${temp[3]})" ttyLeft=$
    {ttyLine% user*
    } ttyNum=$
    {ttyLeft##*,
    } userCnt=$
    {ttyNum##* 
    }   # Write details to the Log File # ----------------------------- print 
    "$date|$time|$cpu|$mem|${dataLine}u|${userCnt}|t|${t[0]}|${t[1]}|$diskLine" >> $logFile   # Clean up the old temporary files # -------------------------------- 
    
    if [[ -f /tmp/vmstat.$$ ]]; then rm /tmp/vmstat.$$ fi 
    
    if [[ -f /tmp/iostat.$$ ]]; then rm /tmp/iostat.$$ fi 
    
    if [[ -f /tmp/uptime.$$ ]]; then rm /tmp/uptime.$$ fi
    

    #AIX-Forum