Monday, May 4, 2009

iostat disk throughput script

Here's a script that can be used to visualize iostat disk throughput which will normally be in columns...

#!/usr/bin/perl -w

use strict;
my $bar_char="=";
my @data;
my $current_read;
my $current_write;
my @dev_len;

my $iostat_lines=0;
open (IOSTATTEST, "iostat -x|");
while(){$iostat_lines++};
print "iostat lines: $iostat_lines\n";
system("clear");

my $current_line=0;
open (IOSTAT, "iostat -x 5|");
while (){
if ($current_line == $iostat_lines){system("clear"); $current_line=0;}
if ($_ =~/\d/){
@data=split(/\s+/,$_);
$current_read=bar($data[3]);
$current_write=bar($data[4]);
@dev_len=split(//,$data[0]);
my $space=" ";
if ($#dev_len == 2){$space=" "};
print "$data[0]$space kb/s r $current_read $data[3]\n";
print "$data[0]$space kb/s w $current_write $data[4]\n";
}
$current_line++;
}

sub bar(){
my $in=$_[0];
my $char="=";
my $blength=($in / 100);
my $rval=$char;
while ($blength > -1){
$rval="$rval"."$char";
$blength=$blength - 1 ;
}
return $rval;
}

Sample output will be as such:

dad0 kb/s r =========== 848.4
dad0 kb/s w ==================== 1764.1
dad1 kb/s r ============ 935.8
dad1 kb/s w ==================== 1789.7
md0 kb/s r == 0.0
md0 kb/s w == 0.0
md1 kb/s r == 0.0
md1 kb/s w == 0.0
md2 kb/s r == 0.0
md2 kb/s w == 0.0
md10 kb/s r == 0.0
md10 kb/s w == 0.0
md11 kb/s r == 0.0
md11 kb/s w == 0.0
md12 kb/s r == 0.0
md12 kb/s w == 0.0
md30 kb/s r ==================== 1784.2
md30 kb/s w ==================== 1763.2
md31 kb/s r =========== 848.4
md31 kb/s w ==================== 1763.2
md32 kb/s r ============ 935.8
md32 kb/s w ==================== 1788.8
md50 kb/s r == 0.0
md50 kb/s w === 0.8
md51 kb/s r == 0.0
md51 kb/s w === 0.8
md52 kb/s r == 0.0
md52 kb/s w === 0.8

credits to www.networkz.ch for the scrips.

Readers who read this page, also read:




Bookmark and Share My Zimbio http://www.wikio.com

0 comments: