Unix Code - Detail View


Date

Name

Plattform

Language

Kurzbeschreibung

Owner

Link

19.10.2001

iostat.awk

Unix

Shell

Executing iostat Command

IBM Corp. 2000

ftp://www.redbooks.ibm.com/redbooks/sg246012

DB2 ist ein Produkt der
IBM Corporation. Bitte
Copyright-  und Trademark-Hinweise beachten!

# iostat_disk.awk
# Raanon Reutlinger, IBM Israel, May 2000

BEGIN{
HEADCOUNTMAX=10;  # Heading every x lines
ONLYPEAKS=ENVIRON[ "ONLYPEAKS"];  # All changes or all Peaks
#ALLCHANGES=ENVIRON[ "ALLCHANGES"];# All changes or all Highest
IOWAIT="IOWAIT";  # Heading for IOWAIT
changedflag=0;
firstdisk="";
lastdisk="";
last_iowait=0;
cnt=0;
if (ONLYPEAKS == "1")
ALLCHANGES=0;
else
ALLCHANGES=1;  # Default is ALLCHANGES=YES
}

/^Disks:/ || /^$/{ next }

/^tty:/{

++cnt;
get_iowait=1;
next;
}

get_iowait{

get_iowait=0;
iowait=$NF;
next;
}

(cnt == 1){ lastdisk=$1 }

# Skip the first two entries of every disk - ramp up of values
(cnt > 2){

if ( (iowait > 0) && ( ALLCHANGES || (iowait > last_iowait) ) )
{
changed[IOWAIT]=cnt;
reads[IOWAIT]=iowait;
writes[IOWAIT]=iowait;
last_iowait=iowait;
changedflag=1;
}
if ( ($5 > 0) && ( ALLCHANGES || ($5 > reads[$1]) ) )
{
changed[$1]=cnt;
reads[$1]=$5;
changedflag=1;
}
if ( ($6 > 0) && ( ALLCHANGES || ($6 > writes[$1]) ) )
{
changed[$1]=cnt;
writes[$1]=$6;
changedflag=1;
}
}

($1 == lastdisk) && (changedflag){  display_results( "-" ) }

END{
if (! ALLCHANGES)
{
headcount = HEADCOUNTMAX - 1;
display_results( "=" );
}
}

##########################
function display_results( underline_char )
{
# Build heading, then replace spaces with dashes
headcount+=1;
headline1="";
for (disk in changed)
if (changed[disk] > 0)
headline1 = headline1 sprintf( " %-9.9s", disk);
gsub( / /, underline_char, headline1);
if ( (headline1 != headline) || (headcount == HEADCOUNTMAX) )
{
headline = headline1;
print headline;
headcount=0;
}

display( "R", reads);
display( "W", writes);
changedflag=0;
}

###########################
function display( RW, activity )
{
got_activity=0;
line="";
for (disk in changed)
{
if (changed[disk] > 0)
{
    if ( (activity[disk]) && (changed[disk] || ! ALLCHANGES))
    {
line = line sprintf( "%s%9s", RW, activity[disk]);
if (disk != IOWAIT)
got_activity=1;
    }
    else
line = line sprintf( "%s%9s", RW, "");
    RW="|";
}
if (ALLCHANGES)
activity[disk]="";
}
if (got_activity)
print line;
}

© Gernot Ruban