Linux – How to get total read and total write IOPS in Linux

diskiolinuxreadwrite

How do I get read and write IOPS separately in Linux, using command line or in a programmatic way? I have installed sysstat package.

Please tell me how do I calculate these separately using sysstat package commands.

Or, is it possible to calculate them using file system?

ex: /proc or /sys or /dev

Best Answer

iostat is part of the sysstat package, which is able to show overall iops if desired, or show them separated by reads/writes.

Run iostat with the -d flag to only show the device information page, and -x for detailed information (separate read/write stats). You can specify the device you want information for by simply adding it afterwards on the command line.

Try running iostat -dx and looking at the summary to get a feel for the output. You can also use iostat -dx 1 to show a continuously refreshing output, which is useful for troubleshooting or live monitoring,

Using awk, field 4 will give you reads/second, while field 5 will give you writes/second.

Reads/second only:

iostat -dx <your disk name> | grep <your disk name> | awk '{ print $4; }'

Writes/sec only:

iostat -dx <your disk name> | grep <your disk name> | awk '{ print $5; }'

Reads/sec and writes/sec separated with a slash:

iostat -dx <your disk name> | grep <your disk name> | awk '{ print $4"/"$5; }'

Overall IOPS (what most people talk about):

iostat -d <your disk name> | grep <your disk name> | awk '{ print $2; }'

For example, running the last command with my main drive, /dev/sda, looks like this:

dan@daneel ~ $ iostat -dx sda | grep sda | awk '{ print $4"/"$5; }' 15.59/2.70

Note that you do not need to be root to run this either, making it useful for non-privileged users.

TL;DR: If you're just interested in sda, the following command will give you overall IOPS for sda:

iostat -d sda | grep sda | awk '{ print $2; }'

If you want to add up the IOPS across all devices, you can use awk again:

iostat -d | tail -n +4 | head -n -1 | awk '{s+=$2} END {print s}'

This produces output like so:

dan@daneel ~ $ iostat -d | tail -n +4 | head -n -1 | awk '{s+=$2} END {print s}' 18.88

Related Question