Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Using the shell to monitor disk activity - read/write rates

I've hit a 'thought wall'.

I'm requiring a script which grabs the current 'data read/sec' and 'data written/sec' as shown in Activity Monitor.

...but I can't recall /what the/if there is a/ command to do such a thing.


I have a previous script to monitor ethernet traffic averages over set periods of time, but the traffic I'm needing to monitor just now is running over Fibre Channel - and as such the most important line of my script is, to put it succinctly, useless. 😟

Thanks in advance 🙂

Xserve, Mac OS X (10.6.4), 32GB RAM, 8G ATTO FC, Infortrend RAIDs

Posted on Mar 11, 2011 3:46 PM

Reply
4 replies

Mar 11, 2011 5:06 PM in response to Camelot

That's fantastic, and exactly what I need - for disk1.

I've got the output but need to get an average from it, and was wanting to use awk, but I'm missing something - as usual 😟

This page ( http://snippets.aktagon.com/snippets/15-Log-file-analysis-with-AWK-Calculating-t he-sum-and-average) has an interesting idea but of course combining things and all the quotations are confusing the heck out of me!

iostat -c 5 -w 10 disk1 | awk "{print $3}" | sed 1d | sed 1d

The above line gets the raw data I want (excluding the top two lines, 'MB/s' and 'load'.. but combining it with another awk command is where I fail.

I've tried slapping it in to an array but it doesn't seem to calculate correctly. My shell scripting knowledge knows many bounds apparently.

How would I go about obtaining a line to produce the average of the values?

Mar 11, 2011 10:34 PM in response to fluffels

How would I go about obtaining a line to produce the average of the values?


Since you're already using awk, let it do the hard work:

iostat -c 5 -w 10 disk1 | awk ' {if (NR>3) {sum += $3; count +=1;} } END {print sum/count} '


This uses awk 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.

Mar 12, 2011 5:24 AM in response to fluffels

How would I go about obtaining a line to produce the average of the values?


Remote server monitoring isn't something you need to personally invent.

Given the nature of the requirement, I'd probably go look for somebody that's already done this.

Nagios is a common remote network monitor, and there are other undoubtedly other tools for this task. Look to see if NRPE can monitor this stuff; I know there are disk storage monitors around for this and other tools, and it wouldn't surprise me to find disk I/O rate monitors available, too.

There are likely also Perl PODs for this, as well as Python/Ruby/Lua/php code, and have a look at [Lithium5|http://lithiumcorp.com> and other options; something built on [Puppet|http://www.puppetlabs.com> might fit.

Ten or twenty years ago, sure, we had to write this stuff for our own requirements and environments. Now? Not so much. It's usually already written, or what's available can be adapted.

Using the shell to monitor disk activity - read/write rates

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.