{"id":16011,"date":"2023-10-12T10:55:12","date_gmt":"2023-10-12T05:25:12","guid":{"rendered":"https:\/\/www.binarytides.com\/?p=16011"},"modified":"2023-10-12T11:20:52","modified_gmt":"2023-10-12T05:50:52","slug":"iostat-command-examples-in-linux","status":"publish","type":"post","link":"https:\/\/www.binarytides.com\/iostat-command-examples-in-linux\/","title":{"rendered":"13 &#8220;iostat&#8221; Command Examples in Linux &#8211; Monitor disk i\/o and cpu usage"},"content":{"rendered":"<p>The iostat command is a system monitoring tool in Linux that provides comprehensive usage information on input\/output (I\/O) devices, partitions, and the CPU. This information can be used in analyzing resource allocation and utilization, identifying potential performance issues, and troubleshooting. <\/p>\t\t<div class=\"display-ad-unit mobile-wide bsa\" style=\"background:#fff3f3; height:315px;\">\n\n<!-- BinaryTides_S2S_InContent_ROS_Pos1 -->\n<style>\n\t@media only screen and (min-width: 0px) and (min-height: 0px) {\n\t\tdiv[id^=\"bsa-zone_1611170977806-3_123456\"] {\n\t\t\tmin-width: 300px;\n\t\t\tmin-height: 250px;\n\t\t}\n\t}\n\t@media only screen and (min-width: 640px) and (min-height: 480px) {\n\t\tdiv[id^=\"bsa-zone_1611170977806-3_123456\"] {\n\t\t\tmin-width: 300px;\n\t\t\tmin-height: 250px;\n\t\t}\n\t}\n<\/style>\n<div id=\"bsa-zone_1611170977806-3_123456\"><\/div>\n\n\n<\/div>\n<!-- Time: 0.00011396408081055, Pos: 307, Key: ad_unit_1 -->\n\n\n<p>iostat monitors the active time of I\/O devices in relation to their average transfer rates. It generates these reports mainly by gathering information from the \/proc filesystem, including data related to the system uptime, disk metrics, and system metrics. <\/p>\n<p>Hence, the \/proc filesystem must be mounted for iostat to function optimally.<\/p>\n<p>In this article, we'll cover some handy iostat commands, which you can use to gain valuable insights into your system's performance.<\/p>\n<h3>Types of Reports<\/h3>\n<p>Generally, iostat produces two types of reports:<\/p>\n<ol>\n<li><strong>CPU Utilization Report:<\/strong> This contains information on the overall CPU performance of the system. Metrics tracked include idle CPU time, CPU utilization at the application and kernel level, and CPU wait time. Furthermore, in systems with multiprocessors, the values produced are the total averages among all processors.<\/li>\n<li><strong>Device Utilization Report:<\/strong> This shows information on the utilization of block devices and partitions. Key metrics tracked include read and write requests, wait times for I\/O requests, and data transfer rates.<\/li>\n<\/ol>\n<h3>Install iostat<\/h3>\n<p>To begin using iostat, the sysstat package, a collection of system monitoring tools, which includes iostat must be installed.<\/p>\n<p><strong>For Ubuntu and other Debian-based distributions, run:<\/strong><\/p>\n<pre class=\"terminal\" >sudo apt install sysstat<\/pre>\n<p><strong>On CentOs, Fedora, and RHEL, run:<\/strong><\/p>\n<pre class=\"terminal\" >sudo dnf install sysstat<\/pre>\n<p><strong>On Arch-based distributions, run:<\/strong><\/p>\n<pre class=\"terminal\" >sudo pacman -S sysstat<\/pre>\n<h3>iostat Command Syntax<\/h3>\n<p>Generally, iostat commands have the following syntax:<\/p>\n<pre class=\"terminal\" >iostat  [options]  [devices]  [interval]  [count]<\/pre>\n<ul>\n<li><strong>options:<\/strong> These are flags that customize the behavior of the iostat command. Commonly used options include -c, -h, and -d.<\/li>\n<li><strong>devices:<\/strong> This defines the block devices for which performance metrics will be monitored.<\/li>\n<li><strong>interval:<\/strong> This indicates the duration (in seconds) between successive reports.<\/li>\n<li><strong>count:<\/strong> This indicates the number of times reports are to be generated. If omitted and the interval is specified, reports are continuously generated.<\/li>\n<\/ul>\n<h3>1. Display All Reports<\/h3>\n<p>Issuing the iostat command without additional flags will produce a report showing both CPU and device utilization reports. Furthermore, when invoking iostat for the first time, the report produced usually shows information from when the system was booted. However, subsequent reports cover the period since the last report was made.<\/p>\n<pre class=\"terminal\" >iostat\r\n\r\nLinux 6.2.0-33-generic (ubuntu-virtual-machine) \t01\/10\/2023 \t_x86_64_(2 CPU)\r\n\r\navg-cpu:  %user   %nice   %system   %iowait    %steal   %idle\r\n           6.83    0.43      8.24      0.22      0.00   84.27\r\n\r\nDevice      tps    kB_read\/s    kB_wrtn\/s    kB_dscd\/s    kB_read    kB_wrtn    kB_dscd\r\nloop0       0.04      0.04        0.00         0.00           17          0         0\r\nloop1       0.12      0.90        0.00         0.00          350          0         0\r\nloop2       0.64      7.69        0.00         0.00         2986          0         0\r\nloop3       0.13      0.93        0.00         0.00          360          0         0\r\nloop4       0.14      2.75        0.00         0.00         1068          0         0\r\nsda        47.78   1612.70      106.36         0.00       626452      41317         0\r\nsdb         0.62     14.48        0.27         0.00         5624        104         0\r\nsr0         0.16      5.39        0.00         0.00         2092          0         0\r\nsr1         0.16      5.40        0.00         0.00         2096          0         0<\/pre>\t\t<div class=\"display-ad-unit mobile-wide bsa\" style=\"background:#fff3f3; height:315px;\">\n\n\n<!-- BinaryTides_S2S_InContent_ROS_Pos2 -->\n<style>\n\t@media only screen and (min-width: 0px) and (min-height: 0px) {\n\t\tdiv[id^=\"bsa-zone_1611334361252-4_123456\"] {\n\t\t\tmin-width: 300px;\n\t\t\tmin-height: 250px;\n\t\t}\n\t}\n\t@media only screen and (min-width: 640px) and (min-height: 480px) {\n\t\tdiv[id^=\"bsa-zone_1611334361252-4_123456\"] {\n\t\t\tmin-width: 300px;\n\t\t\tmin-height: 250px;\n\t\t}\n\t}\n<\/style>\n<div id=\"bsa-zone_1611334361252-4_123456\"><\/div>\n\n\n<\/div>\n<!-- Time: 0.00024700164794922, Pos: 4795, Key: ad_unit_2 -->\n\n\n<p>The output produced above shows two tables \u2014 the first table represents the CPU utilization report, while the second table is the device utilization report for all block devices and partitions the system uses.<\/p>\n<p>The CPU utilization report highlights the following information:<\/p>\n<ul>\n<li><strong>%user:<\/strong> This column indicates the percentage of CPU time spent executing processes at the user level.<\/li>\n<li><strong>%nice:<\/strong> This shows the percentage of CPU time spent executing processes with a nice priority.<\/li>\n<li><strong>%system:<\/strong> This represents the percentage of CPU time spent executing system-level (kernel) tasks.<\/li>\n<li><strong>%iowait:<\/strong> This shows the percentage of CPU time during which the CPU was idle, waiting for the completion of I\/O operations. Furthermore, high values could indicate that the CPU was expecting data from storage devices.<\/li>\n<li><strong>%steal:<\/strong> In a virtualized environment, this represents the percentage of CPU time spent waiting while the underlying hypervisor serviced another virtual machine.<\/li>\n<li><strong>%idle:<\/strong> This shows the percentage of time for which the CPU was idle, without executing any active processes. Moreover, the 84% value in the example above indicates that the CPU has sufficient processing capacity.<\/li>\n<\/ul>\n<p>Similarly, the device utilization report highlights the following information:<\/p>\n<ul>\n<li><strong>Device:<\/strong> This column indicates the names of block devices or partitions.<\/li>\n<li><strong>tps:<\/strong> This shows the number of transfers sent to the device per second. In other words, it represents the I\/O requests sent to the device.<\/li>\n<li><strong>kB_read\/s:<\/strong> Also, MB_read\/s or Blk_read\/s depending on the unit used. It indicates the amount of data read from a device, expressed in kilobytes, megabytes, or blocks per second.<\/li>\n<li><strong>kB_wrtn\/s:<\/strong> Also, MB_wrtn\/s or Blk_wrtn\/s. It shows the amount of data written to a device, expressed in kilobytes, megabytes, or blocks per second.<\/li>\n<li><strong>kB_dscd\/s:<\/strong> Also, MB_dscd\/s or Blk_dscd\/s. This represents the amount of discarded data for a block device, expressed in kilobytes, megabytes, or blocks per second.<\/li>\n<li><strong>kB_read:<\/strong> Also, MB_read or Blk_read. This indicates the total amount of data retrieved from a block device since boot, expressed in kilobytes, megabytes, or blocks.<\/li>\n<li><strong>kB_wrtn:<\/strong> Also, MB_wrtn or Blk_wrtn. This shows the total amount of data written to a block device since boot, expressed in kilobytes, megabytes, or blocks.<\/li>\n<li><strong>kB_dscd:<\/strong> Also MB_dscd or Blk_dscd. This shows the total amount of data discarded for a block device since boot, expressed in kilobytes, megabytes, or blocks.<\/li>\n<\/ul>\n<p>Additionally, the <strong>\"-p\"<\/strong> flag can be added to the command, which instructs iostat to include partitions in the generated report.<\/p>\t\t<div class=\"display-ad-unit mobile-wide bsa\" style=\"background:#fff3f3; height:315px;\">\n<!-- BinaryTides_S2S_InContent_ROS_Pos3 -->\n<style>\n\t@media only screen and (min-width: 0px) and (min-height: 0px) {\n\t\tdiv[id^=\"bsa-zone_1672330111515-1_123456\"] {\n\t\t\tmin-width: 300px;\n\t\t\tmin-height: 250px;\n\t\t}\n\t}\n\t@media only screen and (min-width: 640px) and (min-height: 480px) {\n\t\tdiv[id^=\"bsa-zone_1672330111515-1_123456\"] {\n\t\t\tmin-width: 300px;\n\t\t\tmin-height: 250px;\n\t\t}\n\t}\n<\/style>\n<div id=\"bsa-zone_1672330111515-1_123456\"><\/div>\n<\/div>\n<!-- Time: 0.00012302398681641, Pos: 8372, Key: ad_unit_3 -->\n\n\n<pre class=\"terminal\" >iostat -p\r\n\r\nLinux 6.2.0-33-generic (ubuntu-virtual-machine) \t01\/10\/2023 \t_x86_64_(2 CPU)\r\n\r\navg-cpu:  %user   %nice   %system   %iowait    %steal   %idle\r\n           6.83    0.43      8.24      0.22      0.00   84.27\r\n\r\nDevice      tps    kB_read\/s    kB_wrtn\/s    kB_dscd\/s    kB_read    kB_wrtn    kB_dscd\r\nloop0       0.04      0.04        0.00         0.00           17          0        0\r\nloop1       0.12      0.90        0.00         0.00          350          0        0\r\nloop2       0.64      7.69        0.00         0.00         2986          0        0\r\nloop3       0.13      0.93        0.00         0.00          360          0        0\r\nloop4       0.14      2.75        0.00         0.00         1068          0        0\r\nsda         9.79    109.64       42.26         0.00       629080     242477        0\r\nsda1        0.00      0.02        0.00         0.00          104          0        0\r\nsda2        0.03      0.99        0.00         0.00         5688          1        0\r\nsda3        9.74    108.25       42.26         0.00       621100     242476        0\r\nsdb         0.04      0.98        0.02         0.00         5624        104        0\r\nsdb1        0.00      0.18        0.00         0.00         1040          0        0\r\nsr0         0.16      5.39        0.00         0.00         2092          0        0\r\nsr1         0.16      5.40        0.00         0.00         2096          0        0<\/pre>\n<p>From the output above, the partitions \u2014 sda1, sda1, sda3, and sdb1 are now included in the report.<\/p>\n<h3>2. Show Only CPU Utilization Report<\/h3>\n<p>Generally, invoking the iostat command produces both types of reports. However, you can instruct iostat to show only the CPU utilization report by adding the <strong>\"-c\"<\/strong> flag.<\/p>\n<pre class=\"terminal\" >iostat -c\r\n\r\nLinux 6.2.0-33-generic (ubuntu-virtual-machine)  01\/10\/2023  _x86_64_  (2 CPU)\r\n\r\navg-cpu:  %user   %nice  %system   %iowait   %steal    %idle\r\n          2.00     0.03     2.29      0.05     0.00    95.63<\/pre>\n<h3>3. Show Only Device Utilization Report<\/h3>\n<p>Similarly, you can instruct iostat to show only the device utilization report by adding the <strong>\"-d\"<\/strong> flag instead.<\/p>\n<pre class=\"terminal\" >iostat -d\r\n\r\nLinux 6.2.0-33-generic (ubuntu-virtual-machine) \t01\/10\/2023 \t_x86_64_\t(2 CPU)\r\n\r\nDevice      tps    kB_read\/s    kB_wrtn\/s    kB_dscd\/s    kB_read    kB_wrtn    kB_dscd\r\nloop0       0.04      0.04         0.00          0.00          17         0          0\r\nloop1       0.12      0.90         0.00          0.00         350         0          0\r\nloop2       0.64      7.69         0.00          0.00        2986         0          0\r\nloop3       0.13      0.93         0.00          0.00         360         0          0\r\nloop4       0.14      2.75         0.00          0.00        1068         0          0\r\nsda        47.78   1612.70       106.36          0.00      626452     41317          0\r\nsdb         0.62     14.48         0.27          0.00        5624       104          0\r\nsr0         0.16      5.39         0.00          0.00        2092         0          0\r\nsr1         0.16      5.40         0.00          0.00        2096         0          0<\/pre>\t\t<div class=\"display-ad-unit mobile-wide bsa\" style=\"background:#fff3f3; height:315px;\">\n\n<!-- BinaryTides_S2S_InContent_ROS_Pos4 -->\n<style>\n\t@media only screen and (min-width: 0px) and (min-height: 0px) {\n\t\tdiv[id^=\"bsa-zone_1672740659643-7_123456\"] {\n\t\t\tmin-width: 300px;\n\t\t\tmin-height: 250px;\n\t\t}\n\t}\n\t@media only screen and (min-width: 640px) and (min-height: 480px) {\n\t\tdiv[id^=\"bsa-zone_1672740659643-7_123456\"] {\n\t\t\tmin-width: 300px;\n\t\t\tmin-height: 250px;\n\t\t}\n\t}\n<\/style>\n<div id=\"bsa-zone_1672740659643-7_123456\"><\/div>\n\n<\/div>\n<!-- Time: 0.00018405914306641, Pos: 12205, Key: ad_unit_4 -->\n\n\n<h3>4. Show Report For Selected Devices<\/h3>\n<p>Sometimes the produced report may be too tedious to go through, especially with the inclusion of several loop devices. However, iostat allows you to generate reports for specific block devices by simply specifying their names.<\/p>\n<p>For example, the following command produces a report for both the \/dev\/sda and \/dev\/sdb block devices. <\/p>\n<pre class=\"terminal\" >iostat sda sdb\r\n\r\nLinux 6.2.0-33-generic (ubuntu-virtual-machine) \t01\/10\/2023 \t_x86_64_\t(2 CPU)\r\n\r\navg-cpu:  %user  %nice  %system  %iowait  %steal   %idle\r\n          1.96    0.03     2.24     0.05   0.00    95.72\r\n\r\nDevice      tps     kB_read\/s    kB_wrtn\/s   kB_dscd\/s  kB_read    kB_wrtn    kB_dscd\r\nsda        9.65     102.59         42.08       0.00      629080     258025          0\r\nsdb        0.02       0.39          0.01       0.00        5624        104          0<\/pre>\n<p>Similarly, reports for a single block device can be produced as follows:<\/p>\n<pre class=\"terminal\" >iostat sda\r\n\r\nLinux 6.2.0-33-generic (ubuntu-virtual-machine) \t01\/10\/2023 \t_x86_64_\t(2 CPU)\r\n\r\navg-cpu:  %user   %nice  %system   %iowait   %steal   %idle\r\n           1.96    0.03     2.24      0.05     0.00   95.72\r\n\r\nDevice      tps     kB_read\/s    kB_wrtn\/s   kB_dscd\/s  kB_read    kB_wrtn    kB_dscd\r\nsda        9.65     102.59         42.08       0.00     629080     258025         0<\/pre>\n<p>Additionally, when you add the <strong>\"-p\"<\/strong> flag to the command, the partitions of the block device are included in the report as demonstrated below.<\/p>\n<pre class=\"terminal\" >iostat -p sda\r\n\r\nLinux 6.2.0-33-generic (ubuntu-virtual-machine) \t01\/10\/2023 \t_x86_64_\t(2 CPU)\r\n\r\navg-cpu:  %user   %nice  %system   %iowait   %steal    %idle\r\n           1.96    0.0      2.24      0.05     0.00    95.72\r\n\r\nDevice      tps     kB_read\/s    kB_wrtn\/s   kB_dscd\/s   kB_read    kB_wrtn    kB_dscd\r\nsda         9.65     102.59         42.08      0.00       629080     258025          0\r\nsda1        0.00       0.02          0.00      0.00          104          0          0\r\nsda2        0.02       0.84          0.00      0.00         5688          1          0\r\nsda3        9.41      91.22         41.90      0.00       621100     285272          0<\/pre>\n<h3>5. Show Metrics Summary<\/h3>\n<p>Assuming you want to retrieve a summary of the metrics generated for all devices or selected devices, iostat allows you to do this easily with the help of the <strong>\"-g\"<\/strong> flag. This flag takes a name argument, which represents the row for the aggregate data produced.<\/p>\n<p>For instance, the command below obtains a summary of I\/O metrics for devices, \/dev\/sda and \/dev\/sdb.<\/p>\n<pre class=\"terminal\" >iostat - g Total sda sdb\r\n\r\nLinux 6.2.0-33-generic (ubuntu-virtual-machine) \t02\/10\/2023 \t_x86_64_\t(2 CPU)\r\n\r\navg-cpu:  %user   %nice  %system   %iowait  %steal    %idle\r\n           1.95    0.07     2.22      0.05    0.00    95.71\r\n\r\nDevice     tps    kB_read\/s  kB_wrtn\/s   kB_dscd\/s    kB_read    kB_wrtn    kB_dscd\r\nsda        8.91     56.95      77.09       0.00        853628    1155449          0\r\nsdb        0.02      0.38       0.01       0.00          5624        104          0\r\nTotal      8.92     57.33      77.10       0.00        859252    1155553          0<\/pre>\t\t<div class=\"display-ad-unit mobile-wide bsa\" style=\"background:#fff3f3; height:315px;\">\n\n<!-- BinaryTides_S2S_InContent_ROS_Pos5 -->\n<style>\n\t@media only screen and (min-width: 0px) and (min-height: 0px) {\n\t\tdiv[id^=\"bsa-zone_1672740746864-5_123456\"] {\n\t\t\tmin-width: 300px;\n\t\t\tmin-height: 250px;\n\t\t}\n\t}\n\t@media only screen and (min-width: 640px) and (min-height: 480px) {\n\t\tdiv[id^=\"bsa-zone_1672740746864-5_123456\"] {\n\t\t\tmin-width: 300px;\n\t\t\tmin-height: 250px;\n\t\t}\n\t}\n<\/style>\n<div id=\"bsa-zone_1672740746864-5_123456\"><\/div>\n\n<\/div>\n<!-- Time: 0.000244140625, Pos: 16086, Key: ad_unit_5 -->\n\n\n<p>In the output above, a new row, Total, which represents the aggregate data for each field is included. <\/p>\n<p>Additionally, the <strong>\"-H\"<\/strong> flag can be combined with the <strong>\"-g\"<\/strong> flag, which instructs iostat to show only the summary row in the output.<\/p>\n<pre class=\"terminal\" >iostat -g  Total  sda sdb -H\r\n\r\nLinux 6.2.0-33-generic (ubuntu-virtual-machine) \t02\/10\/2023 \t_x86_64_\t(2 CPU)\r\n\r\navg-cpu:  %user    %nice    %system    %iowait    %steal     %idle\r\n           1.95     0.07       2.22       0.05      0.00     95.71\r\n\r\nDevice     tps    kB_read\/s  kB_wrtn\/s   kB_dscd\/s   kB_read    kB_wrtn    kB_dscd\r\nTotal      8.92    57.33      77.10       0.00        859252    1155553          0<\/pre>\n<h3>6. Show Report at N Intervals<\/h3>\n<p>So far, you've only worked with a single report history. However, iostat can also produce reports at regular intervals, which allows you to gain real-time insights into the system's performance.<\/p>\n<p>To generate reports after certain intervals, a numeric value, representing the period in seconds between successive reports is added to the command.<\/p>\n<p>For example, the command below produces a device utilization report for the \/dev\/sda block device every 3 seconds.<\/p>\n<pre class=\"terminal\" >iostat -d  sda  3\r\n\r\nLinux 6.2.0-33-generic (ubuntu-virtual-machine) \t02\/10\/2023 \t_x86_64_\t(2 CPU)\r\n\r\nDevice     tps      kB_read\/s    kB_wrtn\/s    kB_dscd\/s    kB_read    kB_wrtn    kB_dscd\r\nsda        8.84       49.17        72.34         0.00       853628    1255801          0\r\n\r\nDevice     tps      kB_read\/s    kB_wrtn\/s    kB_dscd\/s    kB_read    kB_wrtn    kB_dscd\r\nsda        1.00        0.00        12.00         0.00            0         36          0\r\n\r\nDevice     tps      kB_read\/s    kB_wrtn\/s    kB_dscd\/s    kB_read    kB_wrtn    kB_dscd\r\nsda        0.33        0.00         1.33         0.00            0          4          0<\/pre>\n<p>Consequently, a report is continuously generated until an interrupt signal is sent.<\/p>\n<h3>7. Show Report N Times<\/h3>\n<p>If you want to generate a limited number of reports, iostat provides an easy way to achieve this. Basically, the second numeric value passed to the iostat command represents the number of times reports will be produced.<\/p>\n<p>For example, the following command produces device utilization reports for the \/dev\/sda block device 2 times with a 5-second interval.<\/p>\n<pre class=\"terminal\" >iostat -d sda 5  2\r\n\r\niostat -d sda 3\r\n\r\nLinux 6.2.0-33-generic (ubuntu-virtual-machine) \t02\/10\/2023 \t_x86_64_\t(2 CPU)\r\n\r\nDevice    tps      kB_read\/s    kB_wrtn\/s    kB_dscd\/s    kB_read    kB_wrtn    kB_dscd\r\nsda      8.84        49.17        72.34         0.00       853628    1255801          0\r\n\r\nDevice    tps      kB_read\/s    kB_wrtn\/s    kB_dscd\/s    kB_read    kB_wrtn    kB_dscd\r\nsda      1.00         0.00        12.00         0.00            0         36          0<\/pre>\n<h3>8. Remove Inactive Device Metrics<\/h3>\n<p>By default, when iostat generates reports at intervals, the report produced also includes block devices and partitions that may have been inactive during that period. However, iostat allows you to limit generated reports to only active devices by adding the <strong>\"-z\"<\/strong> flag.<\/p>\n<p>For instance, the command below produces a report 3 times in 5-second intervals and filters out any inactive devices.<\/p>\n<pre class=\"terminal\" >iostat -z  5  3\r\n\r\nLinux 6.2.0-33-generic (ubuntu-virtual-machine) \t03\/10\/2023 \t_x86_64_\t(2 CPU)\r\n\r\navg-cpu:  %user   %nice   %system   %iowait   %steal    %idle\r\n           1.89    0.05      2.15      0.05     0.00    95.86\r\n\r\nDevice     tps      kB_read\/s    kB_wrtn\/s    kB_dscd\/s    kB_read    kB_wrtn    kB_dscd\r\nloop0      0.00        0.00          0.00       0.00           17           0          0\r\nloop1      0.00        0.02          0.00       0.00          350           0          0\r\nloop2      0.01        0.16          0.00       0.00         2986           0          0\r\nloop3      0.00        0.02          0.00       0.00          360           0          0\r\nloop4      0.00        0.06          0.00       0.00         1068           0          0\r\nloop5      0.00        0.06          0.00       0.00         1113           0          0\r\nsda        8.81       44.47         69.56       0.00       855852     1338873          0\r\nsdb        0.01        0.29          0.01       0.00         5624         104          0\r\nsr0        0.00        0.11          0.00       0.00         2092           0          0\r\nsr1        0.00        0.11          0.00       0.00         2096           0          0\r\n\r\n\r\navg-cpu:  %user   %nice    %system   %iowait    %steal    %idle\r\n           2.23    0.00       2.84      0.00      0.00    94.92\r\n\r\nDevice     tps      kB_read\/s    kB_wrtn\/s    kB_dscd\/s    kB_read    kB_wrtn    kB_dscd\r\nsda       44.40       0.00        214.40        0.00             0       1072          0\r\n\r\n\r\navg-cpu:  %user   %nice    %system   %iowait    %steal    %idle\r\n           1.82    0.00       1.72      0.00      0.00    96.46\r\n\r\nDevice     tps     kB_read\/s    kB_wrtn\/s    kB_dscd\/s    kB_read    kB_wrtn    kB_dscd\r\nsda        1.20      0.00          9.60        0.00            0          48          0<\/pre>\n<p>In the output above, the first report includes all the devices the system uses. However, subsequent reports contain only the \/dev\/sda block device, which was the only active device during that timespan.<\/p>\n<h3>9. Show Extended Metrics<\/h3>\n<p>The device utilization reports produced so far have shown the abridged version of the table with only 7 metrics. However, the device utilization report is much more extensive than that, containing some vital metrics.<\/p>\n<p>The <strong>\"-x\"<\/strong> flag is used to instruct iostat to show a comprehensive version of the report. Since this information can be a lot, the <strong>\"--pretty\"<\/strong> flag can be added to break the report into sub-reports as demonstrated below.<\/p>\n<pre class=\"terminal\" >iostat sda -x --pretty\r\n\r\nLinux 6.2.0-33-generic (ubuntu-virtual-machine) \t02\/10\/2023 \t_x86_64_\t(2 CPU)\r\n\r\navg-cpu:  %user   %nice    %system    %iowait   %steal      %idle\r\n           1.88    0.04       2.13       0.04     0.00      95.90\r\n\r\n     r\/s     rkB\/s    rrqm\/s   %rrqm     r_await      rareq-sz    Device\r\n    0.73     37.58     0.28    27.40      0.88         51.18       sda\r\n\r\n     w\/s     wkB\/s    wrqm\/s   %wrqm     w_await      wareq-sz   Device\r\n    8.07     65.31     1.30    13.90      1.22          8.10       sda\r\n\r\n     d\/s     dkB\/s    drqm\/s   %drqm     d_await     dareq-sz    Device\r\n    0.00     0.00      0.00     0.00      0.00          0.00       sda\r\n\r\n     f\/s    f_await  aqu-sz    %util     Device\r\n    0.00     0.00      0.01     0.42      sda<\/pre>\n<p>Some important information highlighted in the report includes:<\/p>\n<ul>\n<li><strong>r\/s:<\/strong> This indicates the number of completed read requests per second for the device.<\/li>\n<li><strong>%rrqm:<\/strong> This represents the percentage of read requests merged before being sent to the device. Moreover, high values indicate efficient I\/O operations.<\/li>\n<li><strong>r_wait:<\/strong> This shows the average time (in milliseconds) it takes for read requests sent to the device to be completed.<\/li>\n<li><strong>w\/s:<\/strong> This indicates the number of completed write requests per second for the device.<\/li>\n<li><strong>%wrqm:<\/strong> This shows the percentage of write requests merged before being sent to the device.<\/li>\n<li><strong>w_wait:<\/strong> This shows the average time (in milliseconds) it takes for write requests sent to the device to be completed.<\/li>\n<li><strong>%drqm:<\/strong> This indicates the percentage of discard requests merged before being sent to the device.<\/li>\n<li><strong>aqu-sz:<\/strong> This shows the average queue length of requests waiting to be handled by the device.<\/li>\n<li><strong>%util:<\/strong> This indicates the percentage of time spent by the block device in handling I\/O requests.<\/li>\n<\/ul>\n<h3>10. Change Metrics Unit<\/h3>\n<p>The device utilization report uses kilobytes as the default unit. However, iostat provides two flags <strong>\"\u2014k\"<\/strong> and <strong>\"-m\"<\/strong> for modifying the unit depending on your preference. When the <strong>\"-m\"<\/strong> flag is used, the metrics are expressed in megabytes. Whereas, the <strong>\"-k\"<\/strong> flag sets the metrics in kilobytes.<\/p>\n<p>For example, the following command changes the unit of the produced report to megabytes.<\/p>\n<pre class=\"terminal\" >iostat sda -m\r\n\r\nLinux 6.2.0-33-generic (ubuntu-virtual-machine) \t05\/10\/2023 \t_x86_64_(2 CPU)\r\n\r\navg-cpu:  %user   %nice   %system   %iowait   %steal    %idle\r\n          23.42    0.85     32.80      1.13     0.00    41.81\r\n\r\nDevice     tps    MB_read\/s  MB_wrtn\/s    MB_dscd\/s    MB_read    MB_wrtn    MB_dscd\r\nsda      195.88    7.42       0.30         0.00          522        21             0<\/pre>\n<h3>11. Show Report in Human-readable Format<\/h3>\n<p>Adding the <strong>\"-h\"<\/strong> flag to the iostat command produces a more intuitive report. Specifically, the metrics produced are suffixed with units such as k (kilobytes), m (megabytes), and % for CPU-related metrics.<\/p>\n<pre class=\"terminal\" >iostat -h\r\n\r\nLinux 6.2.0-33-generic (ubuntu-virtual-machine) \t02\/10\/2023 \t_x86_64_\t(2 CPU)\r\n\r\navg-cpu:  %user   %nice    %system    %iowait   %steal     %idle\r\n          4.9%     0.2%       7.0%       0.3%     0.0%     87.5%\r\n\r\n     tps      kB_read\/s    kB_wrtn\/s    kB_dscd\/s    kB_read    kB_wrtn    kB_dscd      Device\r\n     0.01         0.0k         0.0k         0.0k       17.0k       0.0k       0.0k       loop0\r\n     0.05         0.4k         0.0k         0.0k      350.0k       0.0k       0.0k       loop1\r\n     0.05         0.4k         0.0k         0.0k      360.0k       0.0k       0.0k       loop2\r\n     0.06         1.1k         0.0k         0.0k        1.0M       0.0k       0.0k       loop3\r\n     0.25         3.0k         0.0k         0.0k        2.9M       0.0k       0.0k       loop4\r\n     0.06         1.1k         0.0k         0.0k        1.1M       0.0k       0.0k       loop5\r\n    36.63       862.9k         1.2M         0.0k      839.5M       1.1G       0.0k         sda\r\n     0.17         4.3k         0.0k         0.0k        4.1M       0.0k       0.0k         sdb\r\n     0.06         2.1k         0.0k         0.0k        2.0M       0.0k       0.0k         sr0\r\n     0.08         2.1k         0.0k         0.0k        2.0M       0.0k       0.0k         sr1<\/pre>\n<h3>12. Show Report Timestamp<\/h3>\n<p>Adding the <strong>\"-t\"<\/strong> flag to the iostat command ensures that timestamps are included with each report. This allows you to easily track the system's performance over time and to have a timeline for the generated reports.<\/p>\n<pre class=\"terminal\" >iostat -t  sda  4  2\r\n\r\nLinux 6.2.0-33-generic (ubuntu-virtual-machine) \t05\/10\/2023 \t_x86_64_\t(2 CPU)\r\n\r\n05\/10\/2023 04:20:37\r\navg-cpu:  %user   %nice   %system   %iowait   %steal     %idle\r\n          4.17    0.12      5.69      0.30      0.00     89.72\r\n\r\nDevice    tps    kB_read\/s    kB_wrtn\/s    kB_dscd\/s    kB_read    kB_wrtn    kB_dscd\r\nsda      31.79   609.16        975.27        0.00        861341    1379001       0\r\n\r\n05\/10\/2023 04:20:41\r\navg-cpu:  %user   %nice   %system   %iowait    %steal     %idle\r\n          2.45     0.00      3.22      0.00     0.00      94.33\r\n\r\nDevice   tps    kB_read\/s    kB_wrtn\/s    kB_dscd\/s    kB_read    kB_wrtn    kB_dscd\r\nsda     0.00      0.00          0.00        0.00             0          0          0<\/pre>\n<p>The output above includes the timestamps of the reports in human-readable format.<\/p>\n<h3>13. Show Reports in JSON<\/h3>\n<p>Javascript object notation (JSON) is a data interchange format consisting of key-value pairs, which allows data to be parsed easily. It is widely used for sending and receiving data.<\/p>\n<p>iostat supports report generation in JSON, which is achieved by adding the <strong>\"-o\"<\/strong> flag together with the <strong>\"JSON\"<\/strong> argument to the command.<\/p>\n<p>For example, the command below produces reports for the \/dev\/sda block device in JSON format.<\/p>\n<pre class=\"terminal\" >iostat -o JSON sda\r\n\r\n{&quot;sysstat&quot;: {\r\n\t&quot;hosts&quot;: [\r\n\t\t{\r\n\t\t\t&quot;nodename&quot;: &quot;ubuntu-virtual-machine&quot;,\r\n\t\t\t&quot;sysname&quot;: &quot;Linux&quot;,\r\n\t\t\t&quot;release&quot;: &quot;6.2.0-33-generic&quot;,\r\n\t\t\t&quot;machine&quot;: &quot;x86_64&quot;,\r\n\t\t\t&quot;number-of-cpus&quot;: 2,\r\n\t\t\t&quot;date&quot;: &quot;05\/10\/2023&quot;,\r\n\t\t\t&quot;statistics&quot;: [\r\n\t\t\t\t{\r\n\t\t\t\t\t&quot;avg-cpu&quot;:  {&quot;user&quot;: 2.72, &quot;nice&quot;: 0.05, &quot;system&quot;: 3.44, &quot;iowait&quot;: 0.15, &quot;steal&quot;: 0.00, &quot;idle&quot;: 93.64},\r\n\t\t\t\t\t&quot;disk&quot;: [\r\n\t\t\t\t\t\t{&quot;disk_device&quot;: &quot;sda&quot;, &quot;tps&quot;: 17.04, &quot;kB_read\/s&quot;: 255.72, &quot;kB_wrtn\/s&quot;: 429.40, &quot;kB_dscd\/s&quot;: 0.00, &quot;kB_read&quot;: 861453, &quot;kB_wrtn&quot;: 1446541, &quot;kB_dscd&quot;: 0}\r\n\t\t\t\t\t]\r\n\t\t\t\t}\r\n\t\t\t]\r\n\t\t}\r\n\t]\r\n}}<\/pre>\n<p>In the output above, the report produced is shown as a JSON array with the key statistics. The array contains two JSON objects, representing both the CPU utilization report and the device utilization report.<\/p>\n<h3>Conclusion<\/h3>\n<p>To sum up, the iostat command is a valuable tool for monitoring and analyzing both CPU and I\/O device performance in Linux. It offers crucial insights into the utilization, throughput, and responsiveness of devices.<\/p>\n<p>Reports produced by iostat allow you to make informed decisions on resource allocation and identify potential performance issues on your system.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The iostat command is a system monitoring tool in Linux that provides comprehensive usage information on input\/output (I\/O) devices, partitions, and the CPU. This information can be used in analyzing resource allocation and utilization, identifying potential performance issues, and troubleshooting. iostat monitors the active time of I\/O devices in relation to their average transfer rates&#8230;. <span class=\"read-more\"><a href=\"https:\/\/www.binarytides.com\/iostat-command-examples-in-linux\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":16021,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[855,853],"tags":[],"class_list":["post-16011","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-commands","category-server-2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>13 &quot;iostat&quot; Command Examples in Linux - Monitor disk i\/o and cpu usage - BinaryTides<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.binarytides.com\/iostat-command-examples-in-linux\/\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Silver Moon\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"14 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.binarytides.com\/iostat-command-examples-in-linux\/\",\"url\":\"https:\/\/www.binarytides.com\/iostat-command-examples-in-linux\/\",\"name\":\"13 \\\"iostat\\\" Command Examples in Linux - Monitor disk i\/o and cpu usage - BinaryTides\",\"isPartOf\":{\"@id\":\"https:\/\/www.binarytides.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.binarytides.com\/iostat-command-examples-in-linux\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.binarytides.com\/iostat-command-examples-in-linux\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.binarytides.com\/blog\/wp-content\/uploads\/2023\/10\/iostat-command-examples-in-linux.jpg\",\"datePublished\":\"2023-10-12T05:25:12+00:00\",\"dateModified\":\"2023-10-12T05:50:52+00:00\",\"author\":{\"@id\":\"https:\/\/www.binarytides.com\/#\/schema\/person\/ce24c6ddfa0368f9a08bcf46505884dd\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.binarytides.com\/iostat-command-examples-in-linux\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.binarytides.com\/iostat-command-examples-in-linux\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.binarytides.com\/iostat-command-examples-in-linux\/#primaryimage\",\"url\":\"https:\/\/www.binarytides.com\/blog\/wp-content\/uploads\/2023\/10\/iostat-command-examples-in-linux.jpg\",\"contentUrl\":\"https:\/\/www.binarytides.com\/blog\/wp-content\/uploads\/2023\/10\/iostat-command-examples-in-linux.jpg\",\"width\":1920,\"height\":1080,\"caption\":\"Iostat command examples in Linux\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.binarytides.com\/iostat-command-examples-in-linux\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.binarytides.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"13 &#8220;iostat&#8221; Command Examples in Linux &#8211; Monitor disk i\/o and cpu usage\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.binarytides.com\/#website\",\"url\":\"https:\/\/www.binarytides.com\/\",\"name\":\"BinaryTides\",\"description\":\"News, Technology, Entertainment and more\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.binarytides.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.binarytides.com\/#\/schema\/person\/ce24c6ddfa0368f9a08bcf46505884dd\",\"name\":\"Silver Moon\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.binarytides.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/67ac3d58b656585dc0201e900a67f4197eb0c3ef2d1f83dd8f95a0b497cd97da?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/67ac3d58b656585dc0201e900a67f4197eb0c3ef2d1f83dd8f95a0b497cd97da?s=96&r=g\",\"caption\":\"Silver Moon\"},\"description\":\"A Tech Enthusiast, Blogger, Linux Fan and a Software Developer. Writes about Computer hardware, Linux and Open Source software and coding in Python, Php and Javascript. He can be reached at binarytides@gmail.com.\",\"url\":\"https:\/\/www.binarytides.com\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"13 \"iostat\" Command Examples in Linux - Monitor disk i\/o and cpu usage - BinaryTides","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.binarytides.com\/iostat-command-examples-in-linux\/","twitter_misc":{"Written by":"Silver Moon","Est. reading time":"14 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.binarytides.com\/iostat-command-examples-in-linux\/","url":"https:\/\/www.binarytides.com\/iostat-command-examples-in-linux\/","name":"13 \"iostat\" Command Examples in Linux - Monitor disk i\/o and cpu usage - BinaryTides","isPartOf":{"@id":"https:\/\/www.binarytides.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.binarytides.com\/iostat-command-examples-in-linux\/#primaryimage"},"image":{"@id":"https:\/\/www.binarytides.com\/iostat-command-examples-in-linux\/#primaryimage"},"thumbnailUrl":"https:\/\/www.binarytides.com\/blog\/wp-content\/uploads\/2023\/10\/iostat-command-examples-in-linux.jpg","datePublished":"2023-10-12T05:25:12+00:00","dateModified":"2023-10-12T05:50:52+00:00","author":{"@id":"https:\/\/www.binarytides.com\/#\/schema\/person\/ce24c6ddfa0368f9a08bcf46505884dd"},"breadcrumb":{"@id":"https:\/\/www.binarytides.com\/iostat-command-examples-in-linux\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.binarytides.com\/iostat-command-examples-in-linux\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.binarytides.com\/iostat-command-examples-in-linux\/#primaryimage","url":"https:\/\/www.binarytides.com\/blog\/wp-content\/uploads\/2023\/10\/iostat-command-examples-in-linux.jpg","contentUrl":"https:\/\/www.binarytides.com\/blog\/wp-content\/uploads\/2023\/10\/iostat-command-examples-in-linux.jpg","width":1920,"height":1080,"caption":"Iostat command examples in Linux"},{"@type":"BreadcrumbList","@id":"https:\/\/www.binarytides.com\/iostat-command-examples-in-linux\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.binarytides.com\/"},{"@type":"ListItem","position":2,"name":"13 &#8220;iostat&#8221; Command Examples in Linux &#8211; Monitor disk i\/o and cpu usage"}]},{"@type":"WebSite","@id":"https:\/\/www.binarytides.com\/#website","url":"https:\/\/www.binarytides.com\/","name":"BinaryTides","description":"News, Technology, Entertainment and more","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.binarytides.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.binarytides.com\/#\/schema\/person\/ce24c6ddfa0368f9a08bcf46505884dd","name":"Silver Moon","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.binarytides.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/67ac3d58b656585dc0201e900a67f4197eb0c3ef2d1f83dd8f95a0b497cd97da?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/67ac3d58b656585dc0201e900a67f4197eb0c3ef2d1f83dd8f95a0b497cd97da?s=96&r=g","caption":"Silver Moon"},"description":"A Tech Enthusiast, Blogger, Linux Fan and a Software Developer. Writes about Computer hardware, Linux and Open Source software and coding in Python, Php and Javascript. He can be reached at binarytides@gmail.com.","url":"https:\/\/www.binarytides.com\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.binarytides.com\/wp-json\/wp\/v2\/posts\/16011","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.binarytides.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.binarytides.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.binarytides.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.binarytides.com\/wp-json\/wp\/v2\/comments?post=16011"}],"version-history":[{"count":5,"href":"https:\/\/www.binarytides.com\/wp-json\/wp\/v2\/posts\/16011\/revisions"}],"predecessor-version":[{"id":16017,"href":"https:\/\/www.binarytides.com\/wp-json\/wp\/v2\/posts\/16011\/revisions\/16017"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.binarytides.com\/wp-json\/wp\/v2\/media\/16021"}],"wp:attachment":[{"href":"https:\/\/www.binarytides.com\/wp-json\/wp\/v2\/media?parent=16011"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.binarytides.com\/wp-json\/wp\/v2\/categories?post=16011"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.binarytides.com\/wp-json\/wp\/v2\/tags?post=16011"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}