3
* Licensed to the Apache Software Foundation (ASF) under one
4
* or more contributor license agreements. See the NOTICE file
5
* distributed with this work for additional information
6
* regarding copyright ownership. The ASF licenses this file
7
* to you under the Apache License, Version 2.0 (the
8
* "License"); you may not use this file except in compliance
9
* with the License. You may obtain a copy of the License at
11
* http://www.apache.org/licenses/LICENSE-2.0
13
* Unless required by applicable law or agreed to in writing, software
14
* distributed under the License is distributed on an "AS IS" BASIS,
15
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
* See the License for the specific language governing permissions and
17
* limitations under the License.
20
/* This plugin makes call to master node, get the jmx-json document
21
* check the storage capacity remaining on local datanode storage
24
$options = getopt ("h:p:w:c:");
25
if (!array_key_exists('h', $options) || !array_key_exists('p', $options) || !array_key_exists('w', $options)
26
|| !array_key_exists('c', $options)) {
33
$warn=$options['w']; $warn = preg_replace('/%$/', '', $warn);
34
$crit=$options['c']; $crit = preg_replace('/%$/', '', $crit);
36
/* Get the json document */
37
$json_string = file_get_contents("http://".$host.":".$port."/jmx?qry=Hadoop:service=DataNode,name=FSDatasetState-DS-*");
38
$json_array = json_decode($json_string, true);
39
$object = $json_array['beans'][0];
40
$cap_remain = $object['Remaining']; /* Total capacity - any extenal files created in data directories by non-hadoop app */
41
$cap_total = $object['Capacity']; /* Capacity used by all data partitions minus space reserved for M/R */
42
$percent_full = ($cap_total - $cap_remain)/$cap_total * 100;
44
$out_msg = "Capacity:[" . $cap_total .
45
"], Remaining Capacity:[" . $cap_remain .
46
"], percent_full:[" . $percent_full . "]";
48
if ($percent_full > $crit) {
49
echo "CRITICAL: " . $out_msg . "\n";
52
if ($percent_full > $warn) {
53
echo "WARNING: " . $out_msg . "\n";
56
echo "OK: " . $out_msg . "\n";
61
echo "Usage: $0 -h <host> -p port -w <warn%> -c <crit%>\n";