The following example illustrates the use of iostat, each device has three columns of data :
$ iostat -w 1 -d
ad0 acd0 fd0 md0
KB/t tps MB/s KB/t tps MB/s KB/t tps MB/s KB/t tps MB/s
9.09 95 0.84 18.63 35 0.63 0.00 0 0.00 0.00 0 0.00
11.26 89 0.98 19.00 42 0.77 0.00 0 0.00 0.00 0 0.00
11.59 72 0.82 19.00 40 0.73 0.00 0 0.00 0.00 0 0.00
6.11 36 0.21 18.06 36 0.63 0.00 0 0.00 0.00 0 0.00
^C
$
Graphing the data is a matter of taking the third column for the device, and expressing it in relation to the highest value so far.
OpenBSD and NetBSD show stats for up to four devices at a time, FreeBSD for up to as many as will fit onto an 80 character display line (which is the same thing). FreeBSD allows for more devices to be displayed, through the -n devs option, but this is not supported by the other BSDs. However, by naming the devices on the command line, at least there is a choice of which devices to display.
The iostat command doesn't distinguish between reads and writes, so all disk activity is shown in blue on BSD systems.
For the purposes of graphing disk activity, we choose the block figures, which give an indication of how hard the disk is being hammered. Because the figures are cumulative, we calculate the number of blocks read and written since the last time we looked, and express both figures as percentages of the highest total so far; reads are shown in blue, and writes in red.
The four figures given on each line are the counts for the first four IDE (hda, hdb, hdc and hdc) or SCSI disks (sda, sdb, sdc and sdd). SCSI disks are given preference over IDE disks, so if the system has both types of disk listed in /proc/partitions, stats are only kept for the SCSI devices, and not for IDE. Also, the entries in /proc/stat will always have four counts, regardless of whether the devices actually exist; so if the system has a single hard disk hda and a CDROM drive hdc, the hard disk will be the first count, and the CDROM drive the third, while the second and fourth counts will be zero.
The following example shows the relevant parts of /proc/partitions and /proc/stat on a Red Hat 6.2 system with a hard disk and a CDROM drive :
$ grep ' [hs]d.$' /proc/partitions 3 0 6342840 hda 22 0 1073741823 hdc $ $ egrep '^disk_(r|w)blk' /proc/stat disk_rblk 52920 0 510 0 disk_wblk 37050 0 0 0 $Both devices are IDE because the names start with hd. Also, there are no SCSI devices mentioned, so the stats will refer to IDE devices. The hard disk has had 52920 blocks read and 37050 blocks written, the CDROM drive has had 510 blocks read and none written (it's a readonly device).
The following example shows a floppy disk and an IDE hard disk on a Red Hat 7.2 system :
$ grep disk_io /proc/stat disk_io: (2,0):(19,19,23,0,0) (3,0):(90569,24038,417822,66531,1579164) $
Each disk is identified by its major and minor numbers in parentheses. The major number refers to the disk controller, and the minor number identifies the device. From my desktop machine with IDE disks and a server with SCSI disks, I have made the following assumptions :
| Major | Minor | Device |
| 2 | 0 | fd0 |
| 2 | 1 | fd1 |
| 3 | 0 | hda |
| 3 | 1 | hdb |
| 22 | 0 | hdc |
| 22 | 1 | hdd |
| 8 | 0 | sda |
| 8 | 1 | sdb |
Following the major/minor numbers, is a group of five stats, containing the number of reads, number of blocks read, number of writes, and number of blocks written, again in parentheses. The number of blocks read and written are figures three and five in each group. Figures two and four are the read and write counts, I'm not sure what figure one is.
As with 2.2 kernels, the figures are cumulative, so we calculate the differences against the last time we looked, and express both figures as percentages of the highest total difference so far. Reads are shown in blue, writes in red.