43

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

shas
  • 2,578
  • 4
  • 17
  • 31

1 Answers1

74

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

Daneel
  • 888
  • 8
  • 9
  • Thanks Mr.Dannel its useful. if i want to get full system Read/Write IOPS How to get ? – shas Aug 24 '15 at 11:00
  • when i run `iostat -dx 1` i got ans like this `Linux 2.6.35.14-106.fc14.i686 (shashi) 08/24/2015 _i686_ (2 CPU) Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util sda 2.46 13.80 2.27 2.03 136.26 123.91 60.53 0.11 25.77 4.43 1.91 dm-0 0.00 0.00 2.35 0.77 93.07 6.11 31.86 0.17 53.73 2.59 0.81 dm-1 0.00 0.00 1.02 2.83 8.14 22.66 8.00 0.83 214.34 0.60 0.23 dm-2 0.00 0.00 1.37 11.89 34.77 95.14 9.80 1.67 126.06 0.84 1.11` for dm-0,dm-1,dm-2 recursively should i add? – shas Aug 24 '15 at 11:02
  • 1
    I've updated the answer with an overall template and an example for `sda`. If you simply want to see the IOPS for your hard drive, then use that last command for overall IOPS (`iostat -d sda | grep sda | awk '{ print $2; }'`) – Daneel Aug 24 '15 at 11:08
  • No i want separately as u mention in 1st answer. bit confuse with `dm-*` so i asked, i need to perform addition on those partitions – shas Aug 24 '15 at 11:13
  • Ahh, ok. You can use the following command to check what each `dm-x` device is: `lvdisplay|awk '/LV Name/{n=$3} /Block device/{d=$3; sub(".*:","dm-",d); print d,n;}'` - I will update the answer with this, as well as how to add the results. – Daneel Aug 24 '15 at 11:14
  • You can skip the grep and just use awk. `iostat -d sda | grep sda | awk '{ print $2; }'` becomes `iostat -d sda | awk '$1=="sda"{ print $2; }'` or `iostat -d sda | awk '/sda/{ print $2; }'`. The performance overhead is minimal, but I'm a big fan of flattening grep|awk in general. :) – dannysauer Sep 07 '18 at 15:01
  • Shouldn't we sum up `Blk_read/s` and `Blk_wrtn/s` instead of `tps` column to get IOPS? – Tagar Sep 13 '18 at 15:53
  • Useful for monitoring IOPS (for `sda`): `iostat -d 1 sda | grep --line-buffered sda | awk -W interactive '{ print $2; }'` – mkczyk Jun 10 '20 at 10:30
  • Is this the output of IOPS I'm doing right now, or the maximum for my disks? – Freedo Jan 25 '21 at 04:56