0

I am looking for a way to parse an iostat file and grab the time and iowait. My files look like this:

Linux OSWbb v7.3.3
zzz ***Wed Jul 20 19:00:08 EDT 2016
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
          49.62    0.00    2.92   13.71    0.00   33.76

Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util
                sda               0.00    15.00    2.00    8.00     8.00    92.00    20.00     0.02    2.40   1.40   1.40
                dm-0              0.00     0.00    0.00    0.00     0.00     0.00     0.00     


zzz ***Thu Jul 20 19:01:09 EDT 2016
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
          10.33    0.00    7.81   20.26    0.00   61.59

Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util
            sda               0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
            dm-0              0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00

zzz ***Thu Jul 20 19:02:09 EDT 2016
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
          10.33    0.00    7.81   20.26    0.00   61.59

Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util
            sda               0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
            dm-0              0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00

I am looking to grab the time from the first line (zzz) and return the %iowait in multiple files. Any suggestions would be appreciated. Thanks

  • The following gets me close, but I'd like to have just the time and %iowait (19:00:08) displayed: cat <files>|grep -A 2 -B 2 "cpu" – mike Jul 21 '16 at 2:05
0

You could use awk. Choose a pattern that selects the line you want, then extract the field. eg

awk '
/:[0-9][0-9]:/ { time=$5 }
/%iowait/ { getline; iowait=$4; print time, iowait }
'

This matches a line with :<two digits>: and keeps field 5. When it matches a line with %iowait, it reads the next line, and keeps field 4.

  • Thanks, but this command just returns the value under %iowait each time it is encountered. The file I am parsing has the lines 'zzz *** <DATE>' and the output of iostat multiple times. – mike Jul 21 '16 at 12:56
  • Can you edit your post with a longer example showing the repetition, and perhaps removing some of the dm-* lines to keep it short. Also, add what arguments you used for the iostat command, and what OS you are using. – meuh Jul 21 '16 at 13:06
  • Edited. It is part of OSWatcher, so I am not sure of the actual command. I just end up with the text files. The OS is RHEL 6.7. – mike Jul 21 '16 at 13:24
  • Thanks. Perhaps the awk version doesnt understand the {2} syntax. Instead use the similar pattern /:[0-9][0-9]:/, see my edited answer with this. – meuh Jul 21 '16 at 13:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.