This article is part of the following series.
- 6 performance tools you should know in Linux
- 5 Ways to Check disk size in Linux
- 4 Ways to Check Disk Partition with Examples in Linux
- How I Fixed a disk performance issue in Minutes – A Step by Step Guide to Optimize Linux System
In this blog post, I will share two methods that I used to check disk iops in Linux.
The first method is a tool called iostat. It is a command-line utility that reports CPU statistics and input/output statistics for devices and partitions.
The second method is sar command. It is a useful tool for system monitoring and performance analysis.
Both of these tools are easy to use. Let’s get started!
Table of Contents
Procedure to check disk iops in Linux
- 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.
what is disk IOPS in Linux?
“IOPS” stands for “Input/Output Operations Per Second.” It is a measure of the number of read/write operations that a storage device can perform per second.
This is an important performance metric for storage devices, as it can impact the speed and responsiveness of an application or system that relies on that storage.
For example, our environment is a high-performance database. It requires a storage device with a high IOPS capability to ensure that database queries are processed quickly and efficiently.
A high IOPS number means that a storage device is capable of performing a large number of read and write operations in a very short amount of time.
This can be beneficial for applications and systems that require fast and efficient access to storage resources.
This metric can be helpful in determining the workload, health, and performance of your disk.
IOPS= r/s + w/s
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.
To learn more how to fix disk performance issue, I highly recommend the following guide.
Check Disk IOPS with iostat in Linux
The best command 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 when dealing with disk issues in Linux.
It can provide detailed statistics on various aspects of disk and storage performance, including transfer rates, read/write percentages, and more. This can be particularly useful for identifying bottlenecks.
Another advantage that I have experienced is that the iostat command is highly customizable. It allows users to specify various options and flags to control the output format, refresh rate, and other parameters.
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.
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 I need to check the IOPS for a specific device, such as /dev/sda, I will 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
sda 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 “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.
The iostat command is widely available on most Linux distributions, making it a convenient and accessible tool for system administrators, developers, and other users who need to monitor and optimize their system performance.
Check Disk IOPS with sar command in Linux
The second method we will discuss is using sar command.
It stands for “System Activity Reporter” and provides a wide range of metrics related to system usage, including CPU utilization, memory usage, disk I/O, network activity, and more.
We 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!