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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     1
#!/usr/bin/perl
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     2
# disk stat thru sys/block/<dev>stats
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     3
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     4
$fbase = "/sys/block/";
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     5
$devpattern = qr#^$base(dm-\d+|sd.+)$#i;
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     6
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     7
$sleep = 1;
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     8
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     9
%nodiff = ( 8 => 1 );
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    10
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    11
@header = qw ( dev r-io r-merge r-sect r-tick w-io w-merge w-sect w-tick inflight iotick timeinQ );
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    12
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    13
@devs = grep { s/^\s+|\s+$//g,1 } grep { /$devpattern/ } qx( ls $fbase );
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    14
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    15
while( 1 ) {
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    16
  print chr(27), "[2J", chr(27), '[f';
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    17
  foreach $h (@header) {
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    18
    printf "%-12s ", $h;
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    19
  }
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    20
  print "\n";
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    21
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    22
  for $i ( 0 .. $#devs ) {
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    23
    $s = qx( cat $fbase$devs[$i]/stat ); chomp $s; $s =~ s/^\s+|\s+$//g;
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    24
    @a = split /\s+/, $s;
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    25
  
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    26
    print $devs[$i], "\t";
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    27
    for $j ( 0 ..  $#a ) {
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    28
      if( $nodiff{$j} ) {
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    29
        printf "%12i;", $a[$j];
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    30
      
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    31
      } else {
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    32
        printf "%12i ", $a[$j] - $prev[$i][$j];
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    33
        $prev[$i][$j] = $a[$j];
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    34
      }
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    35
    }
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    36
    print "\n";
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    37
  }
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    38
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    39
  sleep $sleep;
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    40
}