Cover V03, I02
Article
Figure 1
Figure 2
Listing 1

mar94.tar


Listing 1

#!/bin/sh
#-------------------------------------------------------------------------#
#- Author  of this  Program: William Genosa                              -#
#- Program Name and Release: @(#)sysstat  1.4                            -#
#- File  Name  Used by SCCS: s.sysstat                                   -#
#- Date and Time of Release: 1/3/94 10:05:52                             -#
#-                                                                       -#
#- Description and Usage:                                                -#
#-        This script should be run from CRON every 15 minutes to create -#
#- reports based on statistics  gathered  from  the  VMSTAT  and  IOSTAT -#
#- commands.   VMSTAT is used to report about processes,  virtual memory -#
#- usage, paging, interupts, and cpu utilization.   IOSTAT  is  used  to -#
#- report about disk I/O activity and throughput.                        -#
#--------------------------BEGIN PROGRAM----------------------------------#
#- We need to define locations where the reports are to be archived. The -#
#- format  used is similar to the  format used by  SAR. Each report will -#
#- have the day of the month appended to it, (io15 and vm15 for the 15th -#
#- of the month).  This  scheme  automatically creates reports which are -#
#- overwritten every month.  The TIME  variable is used to timestamp the -#
#- output each time the script is run.                                   -#
#----------------------SOME VARIABLE ASSIGNMENTS--------------------------#
IO_OUT=/var/adm/stat/io`date +%d`                   #- IOSTATs out file. -#
VM_OUT=/var/adm/stat/vm`date +%d`                   #- VMSTATs out file. -#
TIME=`date +%H:%M`                                  #- Format of DATE is -#
#- 22:30 = 10:30 pm. -#
#------------------------SET UP THE OUPUT FILES---------------------------#
#- If the two  output files  do not exist,  then they need to be created -#
#- with the header information in the file. If the time is midnight, the -#
#- output files need to be  truncated to remove the information recorded -#
#- from a previous month, and to have the header information re-created. -#
#-------------------------------------------------------------------------#
if [ ! -f "${IO_OUT}" -o "${TIME}" = "00:00" ]      #- Set up the output -#
then                                                #- file for  IOSTAT. -#
echo "Time  Disks:        % tm_act    Kbps       tps    msps\
Kb_read   Kb_wrtn" > ${IO_OUT}
fi

if [ ! -f "${VM_OUT}" -o "${TIME}" = "00:00" ]      #- Set up the output -#
then                                                #- file for  VMSTAT. -#
echo "
Time   Procs    Memory             Page              Faults        Cpu
----   ----- ----------- ------------------------ ------------ -----------
r  b   avm   fre  re  pi  po  fr   sr  cy  in   sy  cs us sy id wa\
\n" > ${VM_OUT}
fi
#----------------------COLLECT IOSTAT STATISTICS--------------------------#
#- This program is being run on an RS-6000.  The LSPV  command generates -#
#- a line of output for each  physical disk drive on the system with the -#
#- first field containing the name of the physical disk.  The  FOR  loop -#
#- runs iostat on each physical disk four times,  every two seconds. The -#
#- first line of output from  IOSTAT  provides cumulative averages since -#
#- the last reboot. This line is filtered out by TAIL  and the remaining -#
#- three lines are piped into AWK which splits each field into an array. -#
#- The values stored in each array are summed and assigned to variables. -#
#- Then each variable is  divided by  three to get an  average  which is -#
#- output by AWK and assigned to the variable IOSTRING which is appended -#
#- to the output file.   Note that the  timestamp is shown only once for -#
#- each stanza of output.                                                -#
#-------------------------------------------------------------------------#
for DISK in `lspv | awk '{print $1}'`               #- Begin  FOR  loop. -#
do
IOSTRING=`iostat ${DISK} 2 4 | grep hdisk | tail -3 | awk '
{                                                 #- Begin AWK script. -#
for (i = 1; i <= 3; ++i)                       #- 4 samples  taken. -#
{                                              #- Begin   AWK  FOR. -#
disk = $1                                      #- For each disk get -#
split($2,act," ");act[i]                       #- % disk is active, -#
split($3,kbp," ");kbp[i]                       #- Number kbyte/sec, -#
split($4,tps," ");tps[i]                       #- Number xfers/sec, -#
split($5,kbr," ");kbr[i]                       #- Kbytes/sec  read, -#
split($6,kbw," ");kbw[i]                       #- Kbytes/sec wrote, -#
acttot += act[i]                               #- Total % activity, -#
kbptot += kbp[i]                               #- Total kbytes/sec, -#
tpstot += tps[i]                               #- Total  xfers/sec, -#
kbrtot += kbr[i]                               #- Total  kb/s read, -#
kbwtot += kbw[i]                               #- Total kb/s wrote, -#
actavg  = acttot / 3                           #- Average activity, -#
kbpavg  = kbptot / 3                           #- Ave   kbytes/sec, -#
tpsavg  = tpstot / 3                           #- Ave    xfers/sec, -#
kbravg  = kbrtot / 3                           #- Ave kb/sec  read, -#
kbwavg  = kbwtot / 3                           #- Ave kb/sec wrote. -#
}                                              #- End AWK FOR loop. -#
}                                                 #- End  AWK  script. -#
END { printf ( "%s %13.1f %9.1f %9.1f %17d %9d\n",  \
disk, actavg, kbpavg, tpsavg, kbravg, kbwavg) }'`

if echo ${IOSTRING} | grep "hdisk0" > /dev/null   #- The first line of -#
then                                              #- output  each time -#
echo "\n${TIME} ${IOSTRING}" >> ${IO_OUT}        #- the script is run -#
else                                              #- will  contain the -#
echo "      ${IOSTRING}" >> ${IO_OUT}            #- timestamp.        -#
fi
done                                                #- End   FOR   loop. -#
#----------------------COLLECT VMSTAT STATISTICS--------------------------#
#- As  with  IOSTAT,  the first  line of  output  from  VMSTAT  provides -#
#- cumulative averages since the last reboot.  This line is filtered out -#
#- with TAIL and the remaing output is piped into  AWK which splits each -#
#- field into an array.   The values stored in the  array are summed and -#
#- assigned to variables.  Then each variable is divided by three to get -#
#- an  average  which  is  output  by  AWK  and assigned to the variable -#
#- VMSTRING  which  is  appended  to  the  output  file.   Note that the -#
#- timestamp is shown for each stanza of output.                         -#
#-------------------------------------------------------------------------#
VMSTRING=`vmstat 2 4 | tail -3 | awk '
{                                                   #- Begin AWK script. -#
for (i = 1; i <= 3; ++i)                       #- 4 samples  taken. -#
{                                              #- Begin   AWK  FOR. -#
split($1,p_r," ");    p_r[i]                  #- Get process runq, -#
split($2,p_b," ");    p_b[i]                  #- Blocked  process, -#
split($3,m_avm," ");m_avm[i]                  #- Free pg space 4K, -#
split($4,m_fre," ");m_fre[i]                  #- Free real mem 4K, -#
split($5,p_re," ");  p_re[i]                  #- Pages  reclaimed, -#
split($6,p_pi," ");  p_pi[i]                  #- Pages  paged  in, -#
split($7,p_po," ");  p_po[i]                  #- Pages paged  out, -#
split($8,p_fr," ");  p_fr[i]                  #- Pages      freed, -#
split($9,p_sr," ");  p_sr[i]                  #- Pages    scanned, -#
split($10,p_cy," "); p_cy[i]                  #- Page Table scans, -#
split($11,f_in," "); f_in[i]                  #- Device interupts, -#
split($12,f_sy," "); f_sy[i]                  #- System     calls, -#
split($13,f_cs," "); f_cs[i]                  #- Context switches, -#
split($14,c_us," "); c_us[i]                  #- CPU in user mode, -#
split($15,c_sy," "); c_sy[i]                  #- CPU in sys  mode, -#
split($16,c_id," "); c_id[i]                  #- CPU   idle  time, -#
split($17,c_wa," "); c_wa[i]                  #- CPU waiting  I/O, -#
p_rtot   +=   p_r[i]                          #- Total   runqueue, -#
p_btot   +=   p_b[i]                          #- Total    blocked, -#
m_avmtot += m_avm[i]                          #- Total page space, -#
m_fretot += m_fre[i]                          #- Total  free  mem, -#
p_retot  +=  p_re[i]                          #- Total   reclaims, -#
p_pitot  +=  p_pi[i]                          #- Total  page  ins, -#
p_potot  +=  p_po[i]                          #- Total page  outs, -#
p_frtot  +=  p_fr[i]                          #- Total freed page, -#
p_srtot  +=  p_sr[i]                          #- Total pages scan, -#
p_cytot  +=  p_cy[i]                          #- Total  PT  scans, -#
f_intot  +=  f_in[i]                          #- Total dev intrpt, -#
f_sytot  +=  f_sy[i]                          #- Total sys  calls, -#
f_cstot  +=  f_cs[i]                          #- Total context sw, -#
c_ustot  +=  c_us[i]                          #- Total CPU in usr, -#
c_sytot  +=  c_sy[i]                          #- Total CPU in sys, -#
c_idtot  +=  c_id[i]                          #- Total  CPU  idle, -#
c_watot  +=  c_wa[i]                          #- Total waiting IO, -#
p_ravg    =  p_rtot   / 3                     #- Ave size of runq, -#
p_bavg    =  p_btot   / 3                     #- Ave proc blocked, -#
m_avmavg  =  m_avmtot / 3                     #- Ave  page  space, -#
m_freavg  =  m_fretot / 3                     #- Ave free  memory, -#
p_reavg   =  p_retot  / 3                     #- Ave reclaimed pg, -#
p_piavg   =  p_pitot  / 3                     #- Ave   page   ins, -#
p_poavg   =  p_potot  / 3                     #- Ave  page   outs, -#
p_fravg   =  p_frtot  / 3                     #- Ave pages  freed, -#
p_sravg   =  p_srtot  / 3                     #- Ave page scanned, -#
p_cyavg   =  p_cytot  / 3                     #- Average PT scans, -#
f_inavg   =  f_intot  / 3                     #- Ave # of dev int, -#
f_syavg   =  f_sytot  / 3                     #- Ave #  sys calls, -#
f_csavg   =  f_cstot  / 3                     #- Ave context swts, -#
c_usavg   =  c_ustot  / 3                     #- Ave CPU usr mode, -#
c_syavg   =  c_sytot  / 3                     #- Ave CPU sys mode, -#
c_idavg   =  c_idtot  / 3                     #- Ave   idle  time, -#
c_waavg   =  c_watot  / 3                     #- Ave waiting  I/O. -#
}                                              #- End AWK FOR loop. -#
}                                                   #- End  AWK  script. -#
END { printf ( "%3d %2d %5d %5d %3d %3d %3d %3d %4d %3d %3d %4d %3d \
%2d %2d %2d %2d\n", p_ravg, p_bavg, m_avmavg, m_freavg, p_reavg, \
p_piavg, p_poavg, p_fravg, p_sravg, p_cyavg, f_inavg, f_syavg, f_csavg, \
c_usavg, c_syavg, c_idavg, c_waavg) }'`

echo "${TIME} ${VMSTRING}" >> ${VM_OUT}             #- Append time+data. -#
#------------------------------END PROGRAM--------------------------------#