-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcheck_multipath.pl
84 lines (63 loc) · 2.37 KB
/
check_multipath.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/perl
use strict;
use constant MPATH => '/sbin/multipath';
use constant IOSTAT => '/usr/bin/iostat';
die "Please run as root for multipath -l to work\n" if $>;
die "No parameters expected for this script.\n" if @ARGV;
open (my $mpath, '-|', MPATH, '-l') or die $!;
my @disknames;
my $largest_disbalance = -1;
while (my $line = <$mpath>)
{ print "\n" if $line =~ / dm-\d+ /;
print $line if $line =~ /^(size=|[0-9a-f]{10,}|\`-\+-)/;
# |- 1:0:0:19 sdu 65:64 active undef running
# `- 2:0:0:19 sdbm 68:0 active undef running
next unless $line =~ / (.-) ([0-9:]+) (\w+)\s+(\d+:\d+) /;
my ($node, $id, $name, $devnum) = ($1,$2,$3,$4);
#print " ($node, $id, $name, $devnum)\n";
push @disknames, $name;
if ($node eq '`-') #if last disk for this multipath
{ open(my $iostat, '-|', IOSTAT, @disknames) or die $!;
my @reads;
while (my $stat = <$iostat>)
{ my @cols = split /\s+/, $stat;
next unless $stat =~ /^(sd\w+|Device:)\s/ && $#cols == 5;
printf "\t\t%-10s %-15s %-15s\n", @cols[0,4,5];
push @reads, $cols[4];
}
undef @disknames;
close $iostat;
my ($min,$max) = (sort {$a<=>$b} @reads)[1,-1]; #index=0 contains column header
if ($min>100_000)
{ my $disbalance = sprintf "%.05f", ($max/$min -1.0);
print "\tDisbalance=$disbalance\%\n";
$largest_disbalance = $disbalance if $disbalance>$largest_disbalance;
}
}
}
close $mpath;
print "\n\nLargest disbalance found $largest_disbalance\% across all multipath devices\n";
print "Only devices with more than 100k reads are accounted for.\n";
exit 0;
=pod
Usage:
$ sudo ./check_multipath.pl
Sample output:
. . .
360060e80160367000001036700007220 dm-4 HITACHI,OPEN-V
size=1.0T features='1 queue_if_no_path' hwhandler='0' wp=rw
`-+- policy='round-robin 0' prio=0 status=active
Device: Blk_read Blk_wrtn
sdco 31222062 360549
sdcx 31223806 360744
Disbalance=0.00006%
360060e80160367000001036700007248 dm-19 HITACHI,OPEN-V
size=1.0T features='1 queue_if_no_path' hwhandler='0' wp=rw
`-+- policy='round-robin 0' prio=0 status=active
Device: Blk_read Blk_wrtn
sdu 3524257571 501740790
sdbm 3526271302 500408445
Disbalance=0.00057%
Largest disbalance found 0.01511% across all multipath devices.
Only devices with more than 100k reads are accounted for.
=cut