Friday, 16 May 2014

Apple: Get Disk IO From Your Mac With UNIX Command

The UNIX command below allows you to get the disk IO from your MacBook.

#!/bin/bash
io=$(iostat -c 5 -w 10 disk1 | awk ' {if (NR>3) {sum += $3; count +=1;} } END {print sum/count} ')
echo "0:$io:OK"

You may get the disk identifier "disk1" using Disk Utility. The function of AWK is to skip the first three lines (if NR>3), it then increments two counters - one for the sum of $3, the other as a simple counter to keep track of how many entries we have. At the END (i.e., after the last line of input) it simply calculates the average.

* Note: The output from the script can be read by Paessler PRTG.


Reference:
Using the shell to monitor disk activity - read/write rates
https://discussions.apple.com/thread/2779418

No comments:

Post a Comment