LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   iostat to print disk usage speed (https://www.linuxquestions.org/questions/linux-newbie-8/iostat-to-print-disk-usage-speed-894584/)

arp99 07-29-2011 11:31 PM

iostat to print disk usage speed
 
Trying to understand grep,sed,awk but maybe its too early for me and also i suspect iostat is not the correct program for exactly what i'm looking for...

The goal is to print only the current read and write speeds of the disk, represented in a numerical value with two separated commands. So for example when writing a file to disk from an external disk, the value reflects the speed of the process.

"iostat -dk sda" prints
Code:

Linux 2.6.38 (Infidel)  07/30/2011      _x86_64_        (4 CPU)

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda              6.68        55.88      215.16    594171    2287812

"iostat -dx sda" prints
Code:

Linux 2.6.38 (Infidel)  07/30/2011      _x86_64_        (4 CPU)

Device:        rrqm/s  wrqm/s    r/s    w/s  rsec/s  wsec/s avgrq-sz avgqu-sz  await  svctm  %util
sda              3.47  108.04    2.68    6.76  123.98  917.78  110.40    0.91  96.17  3.83  3.62

I found this also but it doesn't help me so far..
Code:

http://collectl.sourceforge.net/DiskStats.html
Finally, if the exact speed measurements are impossible, one total usage percentage will be ok.
Any clues are welcome..

Tinkster 07-29-2011 11:57 PM

Hi, welcome to LQ!

Can you explain how the iostat output doesn't match your
requirement? Seems to match your requirement exactly to
my eye ...


Cheers,
Tink

arp99 07-30-2011 12:37 AM

Yea, thats what cross my mind when i saw "kB_read/s" and "kB_wrtn/s" values but after test it when the transfer happens, the numbers remain almost the same.

e.x when copying a file from one external drive with 30-35MBps rate, it's not logical to see only a 0.08 increase in "kB_wrtn/s" value.

Tinkster 07-30-2011 01:33 AM

I think all you need to do is to tack on a '1' at the end
of your iostat invocation, like so:
Code:

iostat -dk sda 1
If you don't want continuous output try
Code:

iostat -dk sda 1 2
One of the things one needs to be aware of w/ the
sysstat package tools is that their first reading
is commonly garbage.




Cheers,
Tink

syg00 07-30-2011 02:27 AM

Quote:

Originally Posted by Tinkster (Post 4429085)
One of the things one needs to be aware of w/ the
sysstat package tools is that their first reading
is commonly garbage.

That's a little (lot) harsh Tink - this is SOP.
Several "monitoring" tools warn of this effect. With no "previous" reading to relate to, the first reading uses the count fields since boot (or process start depending on metric). This skews the result somewhat.

arp99 07-30-2011 02:53 AM

Thank you, i didn't know that.

"1" did the trick in console but i want to add the commands in a monitor script that will invoke them with 1 second interval.
So the "1 2" is the right one for me, but i also need help on how to grep the values of "kB_read/s" and "kB_wrtn/s" only from the second measurement.
Regex is unknown territory for me yet.

Code:

iostat -dk sda 1 2
prints...
Code:

Linux 2.6.38 (Infidel)  07/30/2011      _x86_64_        (4 CPU)

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda              9.31        37.34      449.05    901687  10843324

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda              81.00        0.00    41472.00          0      41472


Tinkster 07-30-2011 04:40 PM

Quote:

Originally Posted by syg00 (Post 4429119)
That's a little (lot) harsh Tink - this is SOP.
Several "monitoring" tools warn of this effect. With no "previous" reading to relate to, the first reading uses the count fields since boot (or process start depending on metric). This skews the result somewhat.

Well ... in situations like using iostat w/o further parameters
the first row of results is always the same, which must be
pretty meaningless for anyone; to me that makes it brain dead,
and I'll stick w/ my view =o}
If it won't add any actual information why don't they suppress
the first row, and print the 2nd (meaningful) one?


Cheers,
Tink

Tinkster 07-30-2011 04:44 PM

Quote:

Originally Posted by arp99 (Post 4429130)
Thank you, i didn't know that.

"1" did the trick in console but i want to add the commands in a monitor script that will invoke them with 1 second interval.
So the "1 2" is the right one for me, but i also need help on how to grep the values of "kB_read/s" and "kB_wrtn/s" only from the second measurement.
Regex is unknown territory for me yet.

Code:

iostat -dk sda 1 2
prints...
Code:

Linux 2.6.38 (Infidel)  07/30/2011      _x86_64_        (4 CPU)

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda              9.31        37.34      449.05    901687  10843324

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda              81.00        0.00    41472.00          0      41472


Assuming your output looks like mine:
Code:

iostat -dk /dev/sda 1 2 | awk 'NR==7{print $3"\t"$4}'
23424.00        0.00

This isn't really a regex thing, just based on position; 7th row,
3rd and 4th field give read & write of the 2 set of actual info.


Cheers,
Tink

arp99 08-01-2011 10:12 PM

It works and as far as i can tell, iostat gives u pretty reliable measurements!

Thank you again


All times are GMT -5. The time now is 05:11 AM.