howtouselinux

2 ways to check disk IOPS in Linux

Table of Contents

In this blog post, I will share two methods that I used to check disk iops in Linux.

The first method is a command-line tool called iostat, and the second method is sar command. Both of these tools are free and easy to use. Let’s get started!

what is disk IOPS in Linux?

Disk IOPS, or input/output operations per second, is a measure of the amount of work that your disk is doing.

High IOPS can indicate that the storage system is being heavily utilized and may be at risk of slowing down or crashing.

This metric can be helpful in determining the workload, health, and performance of your disk.

IOPS= r/s + w/s 

Disk IOPS is essential for ensuring that our system is running efficiently and effectively.

If there is a sudden drop in IOPS, it could indicate a problem with the storage system or with one of the applications running on the system.

By identifying the cause of the problem, we can take steps to resolve it and improve performance.

Related: How I Fixed a disk performance issue in Minutes – A Step by Step Guide to Optimize Linux System

Procedure to check disk iops in Linux

The procedure to get disk iops in Linux is as follows:

  • Open a terminal window.
  • Type fdisk -l to list all of the disks attached to your server.
  • Note the name of the disk you want to check. In this example, we will use /dev/sda.
  • Type iostat -xd 1 /dev/sda to start monitoring I/O statistics.
  • Press Ctrl+C to stop the I/O monitor. The r/s +  w/s in the command output is the IOPS for this disk. 

 

Check Disk IOPS with iostat in Linux

The most convenient way to check disk IOPS in Linux is using the iostat command. It provides statistics on IOPS for all storage devices on the system. It is used to monitor disk workload in real-time.

This tool is part of the sysstat package, which is a collection of Linux system monitoring tools.

This is my favorite command to check the performance of my disks.

The basic syntax of the iostat command is as follows:

iostat [options] [interval [count]]

  • options: options can be used to specify the type of statistics to be displayed, such as disk statistics, CPU utilization statistics, etc.
  • interval: The interval parameter specifies the amount of time in seconds between each report
  • count:The count parameter can be specified in conjunction with the interval parameter. If the count parameter is specified, the value of count determines the number of reports generated at interval seconds apart. If the interval parameter is specified without the count parameter, the iostat command generates reports continuously.

 

As we said above, iostat command would not stop by default if we don’t specify the count. You can simply press the CTRL + C key combination. This will interrupt the execution of the command and return control back to the terminal prompt. 

Let’s see some examples how to use iostat command.

To display disk I/O statistics every 2 seconds for 5 times, the following command can be used:

iostat -xd 2 5

The “-d” option tells iostat to display information about the disk, and the “-x” option tells iostat to display extended statistics.

If we need to check the IOPS for a specific device, such as /dev/sda, we can run the command like this. Here the interval is 3s.

iostat -xd 3 /dev/sda

Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await svctm %util
xvda 0.00 0.00 100 50 50 100 10 3.00 0.00 0.00 5.00

The IOPS for this device xvda is r/s + w/s = 100 + 50 =150

This output can be a bit confusing, so let’s break it down. The “Device” column shows the name of the disk (in this case, xvda).

  • The “rrqm/s” column shows the number of read requests that were merged per second. The “wrqm/s” column shows the number of write requests that were merged per second.
  • The “r/s” column shows the number of reads per second, and the “w/s” column shows the number of writes per second.
  • The “rkB/s” column shows the number of kilobytes read per second, and the “wkB/s” column shows the number of kilobytes written per second.
  • The “avgrq-sz” column shows the average size of each request in sectors.
  • The “avgqu-sz” column shows the average queue length of the requests. The “await” column shows the average time (in milliseconds) that each request spent in the queue.
  • The “svctm” column shows the average service time (in milliseconds) for each request. And finally, the “%util” column shows the percentage of time that the disk was active.

 

If using iostat without the -x option, the IOPS value is output under the tps (transactions per second) column.

Check Disk IOPS with sar command in Linux

The second method we will discuss for checking disk IOPS in Linux is using sar command.

This command is used to collect, report, and save system activity information for historical data.

We first need to make sure that the sysstat package is installed on our system. Once it’s installed, we can use the sar -d command to view disk I/O statistics, including IOPS.

From the output, tps=IOPS.

How to check disk iops with sar command in Linx

  • Install the sysstat package, if it’s not already installed, using the following command: sudo apt-get install sysstat
  • Run the sar command with the -d option to monitor I/O statistics: sar -d
  • The tps column in the output will show the number of blocks read and written to disk per second, which can be used to calculate IOPS.

 

09:20:01 AM DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm %util
09:30:01 AM dev253-0 2.32 0.00 19.90 8.56 0.01 3.32 0.11 0.03
09:30:01 AM dev253-16 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
09:40:01 AM dev253-0 3.13 0.00 28.63 9.15 0.00 1.47 0.06 0.02
09:40:01 AM dev253-16 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
09:50:01 AM dev253-0 3.05 0.00 25.88 8.47 0.01 2.31 0.09 0.03

 

 How to fix disk IO issue in Linux

Here are a few tips to check disk issue:

  • Make sure that your disks are in good condition. If they are damaged or worn out, they will not perform as well.
  • Make sure that your disks are properly configured. If they are not configured correctly, they will not be able to handle the load.

 

If you are having problems with disk io, you can try using a tool like iotop to help identify the problem.

iotop is a Linux tool that allows you to see what processes are using the most I/O. This can be helpful in identifying which process is causing the problem.

You can install iotop using the following command: sudo apt-get install iotop.

Once it is installed, you can use the following command to see which processes are using the most I/O: iotop.

This will show you a list of the processes that are using the most I/O, as well as the amount of I/O that they are using. You can then use this information to try and solve the problem.

If you have any questions, feel free to leave a comment below. Thanks for reading!

Welcome to howtouselinux.com!

Our website is dedicated to providing comprehensive information on using Linux.

We hope you find our site helpful and informative, and we welcome your feedback and suggestions for future content.

Learn More

Facebook
Twitter
LinkedIn