diff --git a/Ceph/Script/queryCephDisks.pl b/Ceph/Script/queryCephDisks.pl index 8ede2a2f0ebbcee301d6a973dab50cf20b9765c1..b29092c98fab68dcaa60ba68211ed9a4a61cb63f 100755 --- a/Ceph/Script/queryCephDisks.pl +++ b/Ceph/Script/queryCephDisks.pl @@ -60,7 +60,7 @@ chomp $_sudo; ### Options our($opt_exec, $opt_exec2, $opt_become, $opt_cluster, $opt_user, $opt_keyring, $opt_monhost, - $opt_json, $opt_thishost, $opt_select, $opt_range, $opt_debug, $opt_h); + $opt_json, $opt_thishost, $opt_sizeOrDev, $opt_devtype, $opt_select, $opt_range, $opt_debug, $opt_h); if (@ARGV > 0) { GetOptions("e=s"=>\$opt_exec, "l=s"=>\$opt_exec2, @@ -71,6 +71,8 @@ if (@ARGV > 0) { "m=s"=>\$opt_monhost, "j" =>\$opt_json, "t" =>\$opt_thishost, + "p" =>\$opt_sizeOrDev, + "w=s"=>\$opt_devtype, "s=f"=>\$opt_select, "r=f"=>\$opt_range, "d" =>\$opt_debug, @@ -115,10 +117,20 @@ if (defined $opt_thishost) { $thisHost = 1; $theJsonString .= "THIS"; } +# 0 is default, group by device class +# 1 group by disk size +my $selectSizeOrDev = 0; +if (defined $opt_sizeOrDev) { + $selectSizeOrDev = 1; +} my $selectSize = 0.; if (defined $opt_select) { $selectSize = $opt_select; } +my $selectType = 0.; +if (defined $opt_devtype) { + $selectType = $opt_devtype; +} my $theJsonStringNum = $theJsonString."NUM"; # unless ($selectSize >= 0.) { @@ -157,6 +169,7 @@ if ($thisHost) { my @_data = `$cephCmd osd df`; chomp @_data; my %dataHash = (); +my %typeHash = (); my %finalHash = (); # Read the array and print the wanted data foreach my $_line (@_data) @@ -167,7 +180,8 @@ foreach my $_line (@_data) my @fields = split(/\s+/, $_line); next unless ($fields[0] =~ /^\d+$/); my $osdNum = $fields[0]; - my $size = $fields[3]; + my $type = $fields[1]; + my $size = $fields[4]; my $sizeLastChar = lc(chop($size)); if ($sizeLastChar eq "t") { $size = $size * 1000.; @@ -178,6 +192,7 @@ foreach my $_line (@_data) } next unless ($size); push (@{$dataHash{$size}}, $osdNum); + push (@{$typeHash{$type}}, $osdNum); } my $lastKey = 0.; @@ -188,42 +203,73 @@ if ($selectSize > 0) { $selectMin = $selectSize * (1. - ($range/100.)); $selectMin = 0 if ($selectMin < 0.); $selectMax = $selectSize * (1. + ($range/100.)); -} +} print "Select: $selectMin - $selectSize - $selectMax\n" if (defined $opt_debug); -foreach my $aKey (sort {$a<=>$b} keys %dataHash) { - next unless $aKey >= $selectMin; - next if $aKey >= $selectMax; - if ( $aKey >= $selectMin && $aKey <= $selectMax ) { - if ( $aKey > ($lastKey * (1. + ($range/100.))) ) { - $lastKey = $aKey; - @{$finalHash{$lastKey}} = (); +if ($selectSizeOrDev > 0) { + foreach my $aKey (sort {$a<=>$b} keys %dataHash) { + next unless $aKey >= $selectMin; + next if $aKey >= $selectMax; + if ( $aKey >= $selectMin && $aKey <= $selectMax ) { + if ( $aKey > ($lastKey * (1. + ($range/100.))) ) { + $lastKey = $aKey; + @{$finalHash{$lastKey}} = (); + } + if ($thisHost) { + foreach my $osdNum (@{$dataHash{$aKey}}) { + push (@{$finalHash{$lastKey}}, $osdNum) if (exists $osdThisHost{$osdNum}); + } + } else { + push (@{$finalHash{$lastKey}}, @{$dataHash{$aKey}}); + } + @{$finalHash{$lastKey}} = sort { $a <=> $b } @{$finalHash{$lastKey}} if (scalar @{$finalHash{$lastKey}}); + } +# + my $aLine = "Key $aKey: "; + foreach (@{$dataHash{$aKey}}) { + $aLine .= " ".$_; } + $aLine .= "\n"; + print $aLine if (defined $opt_debug); + } + print "\n" if (defined $opt_debug); + foreach my $aKey2 (sort {$a<=>$b} keys %finalHash) { + my $aLine = "Key2 $aKey2: "; + foreach (@{$finalHash{$aKey2}}) { + $aLine .= " ".$_; + } + $aLine .= "\n"; + print $aLine if (defined $opt_debug); + } +} else { + foreach my $aKey (sort keys %typeHash) { + next unless $aKey =~ /$selectType/; + @{$finalHash{$aKey}} = (); if ($thisHost) { - foreach my $osdNum (@{$dataHash{$aKey}}) { - push (@{$finalHash{$lastKey}}, $osdNum) if (exists $osdThisHost{$osdNum}); + foreach my $osdNum (@{$typeHash{$aKey}}) { + push (@{$finalHash{$aKey}}, $osdNum) if (exists $osdThisHost{$osdNum}); } } else { - push (@{$finalHash{$lastKey}}, @{$dataHash{$aKey}}); + push (@{$finalHash{$aKey}}, @{$typeHash{$aKey}}); } - @{$finalHash{$lastKey}} = sort { $a <=> $b } @{$finalHash{$lastKey}} if (scalar @{$finalHash{$lastKey}}); - } + @{$finalHash{$aKey}} = sort @{$finalHash{$aKey}} if (scalar @{$finalHash{$aKey}}); # - my $aLine = "Key $aKey: "; - foreach (@{$dataHash{$aKey}}) { - $aLine .= " ".$_; + my $aLine = "Key $aKey: "; + foreach (@{$typeHash{$aKey}}) { + $aLine .= " ".$_; + } + $aLine .= "\n"; + print $aLine if (defined $opt_debug); } - $aLine .= "\n"; - print $aLine if (defined $opt_debug); -} -print "\n" if (defined $opt_debug); -foreach my $aKey2 (sort {$a<=>$b} keys %finalHash) { - my $aLine = "Key2 $aKey2: "; - foreach (@{$finalHash{$aKey2}}) { - $aLine .= " ".$_; + print "\n" if (defined $opt_debug); + foreach my $aKey2 (sort keys %finalHash) { + my $aLine = "Key2 $aKey2: "; + foreach (@{$finalHash{$aKey2}}) { + $aLine .= " ".$_; + } + $aLine .= "\n"; + print $aLine if (defined $opt_debug); } - $aLine .= "\n"; - print $aLine if (defined $opt_debug); } my $_count = 0;