Listing 3 slowdisk
1 #!/opt/esp/common/bin/perl
2
3 use Getopt::Std;
4 use Solaris::Kstat;
5 use Solaris::MapDev qw(:ALL);
6 use POSIX;
7
8 getopts( "i:s:b:h" );
9 die "usage: slowdisk -i<interval> -s<slow> -b<busy> -h\n"
10 if $opt_h;
11
12 $pk = new Solaris::Kstat;
13 $hz = sysconf(_SC_CLK_TCK);
14 @disks = grep(/^s+d/, get_inst_names());
15
16 foreach $dev ( @disks ) {
17 $pk->update();
18 ($mod, $inst) = ($dev =~ /^(s+d)(\d+)$/);
19 %{$prev->{$dev}} = %{$pk->{$mod}->{$inst}->{$dev}};
20 $prev->{$dev}->{utime} = $pk->{unix}->{0}->{system_misc}->{clk_intr};
21 };
22
23 while( 1 ) {
24 sleep( $opt_i || 5 );
25 foreach $dev ( @disks ) {
26 $pk->update();
27 ($mod, $inst) = ($dev =~ /^(s+d)(\d+)$/);
28 %{$curr->{$dev}} = %{$pk->{$mod}->{$inst}->{$dev}};
29 $curr->{$dev}->{utime} =
30 $pk->{unix}->{0}->{system_misc}->{clk_intr};
31 };
32 foreach $dev (keys %{$curr}) {
33 $etime = ($curr->{$dev}->{utime}-$prev->{$dev}->{utime})/$hz;
34 $rps =
35 ($curr->{$dev}->{reads}-$prev->{$dev}->{reads})*1.0/$etime;
36 $wps =
37 ($curr->{$dev}->{writes}-$prev->{$dev}->{writes})*1.0/$etime;
38
39 $hr_etime =
40 ($curr->{$dev}->{wlastupdate}-$prev->{$dev}->{wlastupdate})
41 || 1000000000;
42 $rdwr = $rps+$wps;
43
44 $avw =
45 ($curr->{$dev}->{wlentime}-$prev->{$dev}->{wlentime})/$hr_etime;
46 $avr =
47 ($curr->{$dev}->{rlentime}-$prev->{$dev}->{rlentime})/$hr_etime;
48 $avwait = $rdwr ? ($avw*1000.0)/$rdwr : 0.0;
49 $avserv = $rdwr ? ($avr*1000.0)/$rdwr : 0.0;
50
51 $w_pct =
52 ($curr->{$dev}->{wtime}-$prev->{$dev}->{wtime})*100.0/$hr_etime;
53 $r_pct =
54 ($curr->{$dev}->{rtime}-$prev->{$dev}->{rtime})*100.0/$hr_etime;
55 $svc_t = $avwait+$avserv;
56
57 printf("slow disk detected: %-12s /dev/dsk/%-10s %-8.2f %-8.2f\n",
58 strftime("%T", localtime()), inst_to_dev($dev), $svc_t, $r_pct)
59 if ($svc_t>=($opt_s || 50.0) && $r_pct>=($opt_b || 20.0));
60 %{$prev->{$dev}} = %{$curr->{$dev}};
61 };
62 };
|