#!/usr/bin/perl
# disk stat thru sys/block/<dev>stats
$fbase = "/sys/block/";
$devpattern = qr#^$base(dm-\d+|sd.+)$#i;
$sleep = 1;
%nodiff = ( 8 => 1 );
@header = qw ( dev r-io r-merge r-sect r-tick w-io w-merge w-sect w-tick inflight iotick timeinQ );
@devs = grep { s/^\s+|\s+$//g,1 } grep { /$devpattern/ } qx( ls $fbase );
while( 1 ) {
print chr(27), "[2J", chr(27), '[f';
foreach $h (@header) {
printf "%-12s ", $h;
}
print "\n";
for $i ( 0 .. $#devs ) {
$s = qx( cat $fbase$devs[$i]/stat ); chomp $s; $s =~ s/^\s+|\s+$//g;
@a = split /\s+/, $s;
print $devs[$i], "\t";
for $j ( 0 .. $#a ) {
if( $nodiff{$j} ) {
printf "%12i;", $a[$j];
} else {
printf "%12i ", $a[$j] - $prev[$i][$j];
$prev[$i][$j] = $a[$j];
}
}
print "\n";
}
sleep $sleep;
}