Linux tips and tricks for all users.

Using the iostat command to keep track of disk usage on Linux.

This example shows the iostat command printing information about disk usage on my Linux Mint 14 system.

john@adeptus-mechanicus ~ $ iostat 
Linux 3.5.0-17-generic (adeptus-mechanicus) 	19/01/13 	_x86_64_	(4 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           9.51    0.01    2.01    0.58    0.00   87.89

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda               0.04         3.15         0.00     634168        808
sdb               0.03         0.08         0.07      15609      14218
scd0              0.00         0.00         0.00        384          0
sdc               0.02         1.42         0.00     285780          3
sdg               0.15         3.63         0.00     729908         24
sdh               1.73        19.24        40.66    3873113    8182464
sdi               0.01         0.29         0.00      58696          1

The -c parameter prints the CPU usage chart.

john@adeptus-mechanicus ~ $ iostat -c
Linux 3.5.0-17-generic (adeptus-mechanicus) 	19/01/13 	_x86_64_	(4 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           9.61    0.01    2.00    0.58    0.00   87.80

And the -d parameter displays the hardware usage chart.

john@adeptus-mechanicus ~ $ iostat -d
Linux 3.5.0-17-generic (adeptus-mechanicus) 	19/01/13 	_x86_64_	(4 CPU)

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda               0.04         3.14         0.00     634168        808
sdb               0.03         0.08         0.07      15609      14218
scd0              0.00         0.00         0.00        384          0
sdc               0.02         1.41         0.00     285780          3
sdg               0.15         3.61         0.00     729908         24
sdh               1.73        19.17        40.63    3874805    8215248
sdi               0.01         0.29         0.00      58696          1

Use the -h parameter to display the hardware utilization chart in a human readable format.

john@adeptus-mechanicus ~ $ iostat -h
Linux 3.5.0-17-generic (adeptus-mechanicus) 	19/01/13 	_x86_64_	(4 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           9.66    0.01    2.00    0.57    0.00   87.76

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda
                  0.04         3.13         0.00     634168        808
sdb
                  0.03         0.08         0.07      15609      14218
scd0
                  0.00         0.00         0.00        384          0
sdc
                  0.02         1.41         0.00     285780          3
sdg
                  0.15         3.61         0.00     729908         24
sdh
                  1.73        19.15        40.61    3874805    8218644
sdi
                  0.01         0.29         0.00      58696          1

The iostat command is available in the sysstat package for Debian and other distributions. Type sudo apt-get install sysstat to install this useful utility. A related command is vmstat. This will also print out useful system information.

vmstat example.

john@adeptus-mechanicus ~ $ vmstat 
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa
 1  0  11840 334480 605220 3473196    0    0    14    20   85   15 10  2 88  1

Use the -d parameter in vmstat to print out disk usage information. Kernel version newer than 2.5.70 required.

john@adeptus-mechanicus ~ $ vmstat -d
disk- ------------reads------------ ------------writes----------- -----IO------
       total merged sectors      ms  total merged sectors      ms    cur    sec
ram0       0      0       0       0      0      0       0       0      0      0
ram1       0      0       0       0      0      0       0       0      0      0
ram2       0      0       0       0      0      0       0       0      0      0
ram3       0      0       0       0      0      0       0       0      0      0
ram4       0      0       0       0      0      0       0       0      0      0
ram5       0      0       0       0      0      0       0       0      0      0
ram6       0      0       0       0      0      0       0       0      0      0
ram7       0      0       0       0      0      0       0       0      0      0
ram8       0      0       0       0      0      0       0       0      0      0
ram9       0      0       0       0      0      0       0       0      0      0
ram10      0      0       0       0      0      0       0       0      0      0
ram11      0      0       0       0      0      0       0       0      0      0
ram12      0      0       0       0      0      0       0       0      0      0
ram13      0      0       0       0      0      0       0       0      0      0
ram14      0      0       0       0      0      0       0       0      0      0
ram15      0      0       0       0      0      0       0       0      0      0
loop0      0      0       0       0      0      0       0       0      0      0
loop1      0      0       0       0      0      0       0       0      0      0
loop2      0      0       0       0      0      0       0       0      0      0
loop3      0      0       0       0      0      0       0       0      0      0
loop4      0      0       0       0      0      0       0       0      0      0
loop5      0      0       0       0      0      0       0       0      0      0
loop6      0      0       0       0      0      0       0       0      0      0
loop7      0      0       0       0      0      0       0       0      0      0
sda     8714 162501 1268336   44212    120     82    1616     372      0     29
sdb     3138     90   31218   22524   2041   1030   28436   16540      0      5
sr0      130     62     768    9224      0      0       0       0      0      9
sdc     4851   1718  571560   65344      4      3       7       4      0     19
sdd        0      0       0       0      0      0       0       0      0      0
sde        0      0       0       0      0      0       0       0      0      0
sdf        0      0       0       0      0      0       0       0      0      0
sdg    29456 258350 1459816   88108      4      2      48       0      0     80
sdh   116902 447188 7749674 2103880 233916 315734 16469736 9003876      0   2749
sdi     1110   1320  117393   10684      3      0       3    1480      0      5

The -p parameter will print out information about a partition. Kernel version newer than 2.5.70 required.

john@adeptus-mechanicus ~ $ vmstat -p /dev/sda1
sda1          reads   read sectors  writes    requested writes
                6785    1252408         78        992

Post a Comment

Your email is kept private. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Current day month ye@r *