3

I'm trying to obtain the current disk I/O usage (in %) from a single command.

Currently I have

iostat -dx /dev/sda 1 | awk  {'print $16'}

which gives me the utilization entry for I/O from iostat. It also keeps updating and giving new entries, that's something I don't want:

%util
0.06

%util
0.00

%util
0.09

What i'm trying to get is just a single line that gives the current I/O usage in percentage. so its output would simply look like this:

0.06
dessert
  • 40,956
Roderik
  • 33

1 Answers1

3

This seems to work for me (in the below examples, the first one was taken with nothing else going on, and the second was taken reading a big huge file):

doug@s15:~/iso$ iostat -dxy 2 1 /dev/sda | grep sda | awk  {'print $14'}
0.00
doug@s15:~/iso$ iostat -dxy 2 1 /dev/sda | grep sda | awk  {'print $14'}
100.00

The command takes one sample over a 2 second interval, and ignores the starting statistics.

NOTE: On my computer I had to use the 14th column instead of the 16th.

Doug Smythies
  • 16,146