Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
CSD
public
zabbix-templates
Commits
9606e8ae
Commit
9606e8ae
authored
Apr 05, 2018
by
Fulvio Galeazzi
Browse files
2018-04-05: FG; queryCephDisks now supports device class (Luminous).
parent
c9c4f77b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Ceph/Script/queryCephDisks.pl
View file @
9606e8ae
...
...
@@ -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
(
@
{
$
data
Hash
{
$aKey
}})
{
push
(
@
{
$finalHash
{
$
last
Key
}},
$osdNum
)
if
(
exists
$osdThisHost
{
$osdNum
});
foreach
my
$osdNum
(
@
{
$
type
Hash
{
$aKey
}})
{
push
(
@
{
$finalHash
{
$
a
Key
}},
$osdNum
)
if
(
exists
$osdThisHost
{
$osdNum
});
}
}
else
{
push
(
@
{
$finalHash
{
$
last
Key
}},
@
{
$
data
Hash
{
$aKey
}});
push
(
@
{
$finalHash
{
$
a
Key
}},
@
{
$
type
Hash
{
$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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment