Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A perl script to present summarized iostat output UNIX
iostat provides a means to monitor disk throughput, but the output is rather gross. The below perl script cleans it up. Call it with an interval in seconds. Oddly, the disk numbers don't seem to corespond to what df reports.

#!/usr/bin/perl

use strict;
use POSIX qw(strftime);

my $donedisks=0;
my $increment=shift;
my $fieldRE = '\s+(\d+\.\d+)\s+(\d)+\s+(\d+\.\d+)';

open(FILE,"iostat -n 99 -d -w $increment |") || die "Can't open iostat - $!";
while (<FILE>) {
 chop;
 next if (/KB/);   # ignore header
 if (/disk/) {     # grab disk names
   next if $donedisks++;
   s/^\s+|\s+$//g;
   s/\s+/,/g;
   my $now_string = strftime("%F,%T",localtime(time));
   my @disks = split(/,/); print "#$now_string,$_\n";
   next;
 }

 if (/$fieldRE/) {  # good info!
  my $result='';
  while (/^\s*$fieldRE/) {
    my ($kbt,$tps,$mbs) = ($1,$2,$3);
    s/^\s*$fieldRE//;
    $result .= "$mbs,";
  }
  $result =~ s/,$//;
  my $now_string = strftime("%F,%T",localtime(time));
  print "$now_string,$result\n";
  }
}
close FILE;
[robg adds: At least on 10.3, the iostat output looks fine on my machine, but the above script will give you a nicely condensed version, letting you see many more events on one Terminal screen...]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[6,665 views]  

A perl script to present summarized iostat output | 0 comments | Create New Account
Click here to return to the 'A perl script to present summarized iostat output' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.