disk_io_stat.pl
author Peter Gervai <grin@grin.hu>
Wed, 07 May 2014 16:25:00 +0200
changeset 0 624a9ab34425
permissions -rwxr-xr-x
Add code lying around to the repo

#!/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;
}