disk_io_stat.pl
changeset 0 624a9ab34425
equal deleted inserted replaced
-1:000000000000 0:624a9ab34425
       
     1 #!/usr/bin/perl
       
     2 # disk stat thru sys/block/<dev>stats
       
     3 
       
     4 $fbase = "/sys/block/";
       
     5 $devpattern = qr#^$base(dm-\d+|sd.+)$#i;
       
     6 
       
     7 $sleep = 1;
       
     8 
       
     9 %nodiff = ( 8 => 1 );
       
    10 
       
    11 @header = qw ( dev r-io r-merge r-sect r-tick w-io w-merge w-sect w-tick inflight iotick timeinQ );
       
    12 
       
    13 @devs = grep { s/^\s+|\s+$//g,1 } grep { /$devpattern/ } qx( ls $fbase );
       
    14 
       
    15 while( 1 ) {
       
    16   print chr(27), "[2J", chr(27), '[f';
       
    17   foreach $h (@header) {
       
    18     printf "%-12s ", $h;
       
    19   }
       
    20   print "\n";
       
    21 
       
    22   for $i ( 0 .. $#devs ) {
       
    23     $s = qx( cat $fbase$devs[$i]/stat ); chomp $s; $s =~ s/^\s+|\s+$//g;
       
    24     @a = split /\s+/, $s;
       
    25   
       
    26     print $devs[$i], "\t";
       
    27     for $j ( 0 ..  $#a ) {
       
    28       if( $nodiff{$j} ) {
       
    29         printf "%12i;", $a[$j];
       
    30       
       
    31       } else {
       
    32         printf "%12i ", $a[$j] - $prev[$i][$j];
       
    33         $prev[$i][$j] = $a[$j];
       
    34       }
       
    35     }
       
    36     print "\n";
       
    37   }
       
    38 
       
    39   sleep $sleep;
       
    40 }