disk_io_stat.pl
author Peter Gervai <grin@grin.hu>
Thu, 30 Sep 2021 15:30:10 +0200
changeset 8 31c4ce4d9b73
parent 0 624a9ab34425
permissions -rwxr-xr-x
perlgrok.pl: Fix patternfile; handle perl-incopatible labels * implement per-pattern regex trace

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