The first idea I found is the vmstat -d
command.
It tells you the number of sectors written since booting.
fdisk -l
will tell you the sector size.
By multiplying the two you can get the number of bytes touched.
It seems my computer does roughly 1 gigabytes worth of writing in two hours. By doing a quick calculation a 128G SSD with 3000 write cycles would last 90 years... Nothing to worry about.
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
Best Answer
You can use the tool
iostat
to collect the disk utilization information. It takes several arguments, including the switch,-d
:It also takes an argument in seconds an interval of how frequent it should re-run. The value
3600
would be the number of seconds in an hour.Example
The output from this command could be redirected to a file:
Meaning of the units
If you consult the man page for
iostat
it has pretty good descriptions of the units.excerpt
So a block is 512 bytes, so the Blk_read/s in terms of MB for device
sda
would be, 71.86 * 512 bytes = 36.79232 kilobytes/sec.There are additional switches that will change the units automatically in the output.
excerpt from
iostat
man pageExample in KB/s
So this might be more useful, showing the throughput in KB/s: