AIX Tip of the Week

AIX Tip of the Week: Using awk to Consolidate iostat Output for Spreadsheet Analysis

Audience: AIX Users and Administrators

Date: January 1999

The Unix iostat command lists CPU, Disk, TTY and other system performance data. The output of this command is in a multiline format as shown in the example below. This format is difficult to use with graphing and analysis tools such as spreadsheets.

The iostat output can be converted to a delimited single line format using the iostat.awk program listed below. The new format is suitable for import into spreadsheets and other analysis tools. Although the example below shows three disks, the program will work with any number of disks.


Example:

$ iostat 5 10 > iostat.out

tty: tin tout avg-cpu: % user % sys % idle % iowait 0.0 0.3 0.1 0.4 99.4 0.1 Disks: % tm_act Kbps tps Kb_read Kb_wrtn hdisk0 0.1 0.5 0.1 2065036 2724212 hdisk1 0.0 0.3 0.0 1996500 750946 hdisk2 0.0 0.1 0.0 507701 44156 cd0 0.0 0.0 0.0 104026 0 tty: tin tout avg-cpu: % user % sys % idle % iowait 0.0 0.0 7.3 40.9 0.0 51.8 Disks: % tm_act Kbps tps Kb_read Kb_wrtn hdisk0 40.6 215.2 42.2 352 300 hdisk1 31.4 149.2 38.0 384 68 hdisk2 0.0 0.0 0.0 0 0 cd0 0.0 0.0 0.0 0 0 ...etc....

$ awk -f iostat.awk iostat.out

CPU(Sy+Us) ; I/O Wait ; Disk ; Disk ; Disk 0.5 ; 0.1 ; 0.1 ; 0.0 ; 0.0 ; 48.2 ; 51.8 ; 40.6 ; 31.4 ; 0.0 ; 58.3 ; 41.6 ; 51.2 ; 12.1 ; 0.0 ; 96.3 ; 3.7 ; 6.3 ; 0.0 ; 0.0 ; 99.6 ; 0.3 ; 1.0 ; 0.0 ; 0.0 ; 99 ; 1.0 ; 1.0 ; 0.0 ; 0.0 ; 90 ; 10.0 ; 19.0 ; 0.0 ; 0.0 ; 59.5 ; 40.5 ; 26.6 ; 5.3 ; 30.6 ; 61.7 ; 38.3 ; 2.7 ; 0.3 ; 50.7 ; 69.6 ; 30.3 ; 0.0 ; 0.0 ; 39.3 ; 29 ; 15.0 ; 2.0 ; 0.0 ; 19.0 ; 0 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.6 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.6 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ; Average CPU = 50.92

Note that the program could also have been run as: iostat 5 50 | awk -f iostat.awk

The iostat.awk file is listed below.

# Awk utility to format the output of the iostat command for import to spreadsheet # Usage 1: iostat x y | awk -f iostat.awk # Usage 2: iostat x y > iostat.out # awk -f iostat.awk iostat.out # Comment: this utility is designed to work with any number of disks # Bruce Spencer, IBM 11-25-98 BEGIN { printf("%10s ;%10s ;%10s ;%10s ;%10s","CPU(Sy+Us)","I/O Wait","Disk","Disk","Disk") } ( NF==6 && !/isk/ && !/cd0/ ) { CPU+=$3+$4 COUNT++ printf("\n%10s ;%10s ;", $3+$4, $6) } /hdisk/{ printf("%10s ;",$2) } END { printf("\n\nAverage CPU = %5.2f\n", CPU/COUNT) }