How to calculate disk IO load percentage?
Solution 1
The information you indicate you have is not enough to calculate disk utilization %.
Disk utilization % is calculated as disk_time_spent_in_io / elapsed_time
.
For example, if your disk spends 0.25 seconds performing IO in a 1 second period, then your disk is 25% utilized.
The number of operations is meaningless when it comes to utilization %. Depending on your disk, and the type of IO you're performing (bulk vs random), it could be 100% utilized at 10 IOPS, or 10000 IOPS. The only way to know is by how long the disk is taking to perform those IOPs.
Solution 2
For everybody who searching for a solution, iostat calculates a percentage from /sys/block/sda/stat
. The formula is roughly:
{now,past}_tot_ticks = total time this block device has been active (/sys/block/sda/stat)
{now,past}_uptime = uptime in /proc/uptime (first value)
percentage = (now_tot_ticks - past_tot_ticks) / (now_uptime - past_uptime) / 10
A command to get the IO load in percentage over one second:
$ cat \
<(cat /sys/block/sda/stat && cat /proc/uptime) \
<(sleep 1 && cat /sys/block/sda/stat && cat /proc/uptime) \
| awk -v RS="" '{printf "%.2f%\n", ($27-$10)/($33-$16) / 10}';
Further reading:
[1] https://www.kernel.org/doc/Documentation/block/stat.txt
[2] https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/deployment_guide/s2-proc-uptime
[3] https://github.com/sysstat/sysstat/blob/v11.4.3/iostat.c
Related videos on Youtube
GP92
Updated on September 18, 2022Comments
-
GP92 over 1 year
The following is net-snmp output and as you see, diskIOLA is not availabe:
SNMP table: UCD-DISKIO-MIB::diskIOTable diskIOIndex diskIODevice diskIONRead diskIONWritten diskIOReads diskIOWrites diskIOLA1 diskIOLA5 diskIOLA15 diskIONReadX diskIONWrittenX 25 sda 845276160 2882477056 576632 42597061 ? ? ? 5140243456 883350772736
According to the definitions here http://www.net-snmp.org/docs/mibs/ucdDiskIOMIB.html:
diskIOLAx means the x minute average load of disk (%).
The other values in the table are:
- diskIONRead - The number of bytes read from this device since boot.
- diskIONWritten - The number of bytes written to this device since boot.
- diskIOReads - The number of read accesses from this device since boot.
- diskIOWrites - The number of write accesses to this device since boot
So, how does this load can be calculated manually, as it is not collected in the server?
In the end, we want to show graphs to users where they can find if a disk IO is heavy or not. We can either display this using Read/write bytes/sec or Read/write requests/sec.
If we display Read/write requests/sec alone, we can know that there is heavy I/O going on. But we won't be knowing if the disk R/W speed is effected by this.
And displaying R/W speed alone can't tell us why the speed is effected - whether it is because of too many I/O operations or not enough buffer memory for asynchronous writes. Hence, we need to display both.
But, what is the other value disk IOLoad means and how can we calculate it and why is it not being collected in snmp. Does it cause huge load if enable this? If it cause heavily load collecting this value, then we can calculate it manually. But, what's the formula?