#!/usr/bin/env php
<?php 
require 'lib.php';
$options = getopt("hH:p:S");
//Check only for mandatory options
if (array_key_exists('h', $options) || !array_key_exists('H', $options) || !array_key_exists('p', $options)) {
    usage();
    exit(3);
}
$host = $options['H'];
$port = $options['p'];
$protocol = array_key_exists('S', $options) ? 'https' : 'http';
$object = get_from_jmx($protocol, $host, $port, 'Hadoop:service=NameNode,name=NameNodeInfo');
if (empty($object) || $object['NameDirStatuses'] == '') {
    echo 'CRITICAL: NameNode directory status not available' . PHP_EOL;
    exit(2);
}
$NameDirStatuses = json_decode($object['NameDirStatuses'], true);
$failed_dir_count = count($NameDirStatuses['failed']);
$out_msg = "Offline NameNode directories: ";
if ($failed_dir_count > 0) {
    foreach ($NameDirStatuses['failed'] as $key => $value) {
        $out_msg .= $key . ':' . $value . ', ';
    }
    echo 'CRITICAL: ' . $out_msg . PHP_EOL;
    exit(2);
}
echo 'OK: All NameNode directories are active' . PHP_EOL;
exit(0);
function usage()
{
Esempio n. 2
0
#!/usr/bin/env php
<?php 
require 'lib.php';
$options = getopt("hH:p:S");
if (array_key_exists('h', $options) || !array_key_exists('H', $options) || !array_key_exists('p', $options)) {
    usage();
    exit(3);
}
$host = $options['H'];
$port = $options['p'];
$protocol = array_key_exists('S', $options) ? 'https' : 'http';
$object = get_from_jmx($protocol, $host, $port, 'Hadoop:service=NameNode,name=FSNamesystem');
if (empty($object)) {
    echo 'CRITICAL: Data inaccessible' . PHP_EOL;
    exit(2);
}
$missing_blocks = $object['MissingBlocks'];
$total_blocks = $object['BlocksTotal'];
if ($total_blocks == 0) {
    $m_percent = 0;
} else {
    $m_percent = $missing_blocks / $total_blocks * 100;
}
$out_msg = 'Missing blocks: ' . $missing_blocks . '/' . $total_blocks . ' (' . $m_percent . '%)|missingBlocks=' . $missing_blocks . ';totalBlocks=' . $total_blocks . ';percent=' . $m_percent . '%';
if ($m_percent > 0) {
    echo 'CRITICAL: ' . $out_msg . PHP_EOL;
    exit(2);
}
echo 'OK: ' . $out_msg . PHP_EOL;
exit(0);
/* print usage */
<?php 
require 'lib.php';
$options = getopt("hH:p:w:c:S");
if (array_key_exists('h', $options) || !array_key_exists('H', $options) || !array_key_exists('p', $options) || !array_key_exists('w', $options) || !array_key_exists('c', $options)) {
    usage();
    exit(3);
}
$host = $options['H'];
$port = $options['p'];
$warn = $options['w'];
$warn = preg_replace('/%$/', '', $warn);
$crit = $options['c'];
$crit = preg_replace('/%$/', '', $crit);
$protocol = array_key_exists('S', $options) ? 'https' : 'http';
/* Get the json document */
$object = get_from_jmx($protocol, $host, $port, 'Hadoop:service=DataNode,name=FSDatasetState-*');
if (empty($object)) {
    echo 'CRITICAL: Data inaccessible' . PHP_EOL;
    exit(2);
}
$cap_remain = $object['Remaining'];
/* Total capacity - any extenal files created in data directories by non-hadoop app */
$cap_total = $object['Capacity'];
/* Capacity used by all data partitions minus space reserved for M/R */
$cap_used = $cap_total - $cap_remain;
$percent_used = round($cap_used / $cap_total * 100, 2);
$cap_used_h = round($cap_used / (1024 * 1024 * 1024), 2);
$cap_total_h = round($cap_total / (1024 * 1024 * 1024), 2);
$out_msg = 'Capacity: ' . $cap_total_h . ' GB, Used: ' . $cap_used_h . ' GB (' . $percent_used . '%)|capUsed=' . $cap_used . ';capTotal=' . $cap_total . ';percent=' . $percent_used . '%';
if ($percent_used > $crit) {
    echo 'CRITICAL: ' . $out_msg . PHP_EOL;
#!/usr/bin/env php
<?php 
require 'lib.php';
$options = getopt("hH:p:w:c:n:S");
if (array_key_exists('h', $options) || !array_key_exists('H', $options) || !array_key_exists('p', $options) || !array_key_exists('w', $options) || !array_key_exists('c', $options) || !array_key_exists('n', $options)) {
    usage();
    exit(3);
}
$host = $options['H'];
$port = $options['p'];
$service = $options['n'];
$warn = $options['w'];
$crit = $options['c'];
$protocol = array_key_exists('S', $options) ? 'https' : 'http';
$jmx_response = get_from_jmx($protocol, $host, $port, 'Hadoop:service=' . $service . ',name=RpcActivityForPort*');
if (empty($jmx_response)) {
    echo 'CRITICAL: Data inaccessible' . PHP_EOL;
    exit(2);
}
$queueTime = round($jmx_response['RpcQueueTimeAvgTime'], 2);
$processingTime = round($jmx_response['RpcProcessingTimeAvgTime'], 2);
$out_msg = 'RPC: Queue: ' . $queueTime . ' s, Processing: ' . $processingTime . ' s';
if ($queueTime >= $crit) {
    echo 'CRITICAL: ' . $out_msg . PHP_EOL;
    exit(2);
}
if ($queueTime >= $warn) {
    echo 'WARNING: ' . $out_msg . PHP_EOL;
    exit(1);
}
echo 'OK: ' . $out_msg . PHP_EOL;
Esempio n. 5
0
if (array_key_exists('h', $options) || !array_key_exists('H', $options) || !array_key_exists('p', $options) || !array_key_exists('f', $options) || !array_key_exists('j', $options)) {
    usage();
    exit(3);
}
/* We can use either -r (exact value) or both -w and -c (value limit) */
if (!(array_key_exists('w', $options) && array_key_exists('c', $options)) && !array_key_exists('r', $options)) {
    usage();
    exit(3);
}
$host = $options['H'];
$port = $options['p'];
$field = $options['f'];
$property = $options['j'];
$protocol = array_key_exists('S', $options) ? 'https' : 'http';
/* Get the json document */
$object = get_from_jmx($protocol, $host, $port, 'Hadoop:service=NameNode,name=' . $property);
if (empty($object)) {
    echo 'CRITICAL: Data inaccessible' . PHP_EOL;
    exit(2);
}
$val = array_key_exists($field, $object) ? $object[$field] : false;
$out_msg = $field . ' = ' . $val . '|' . $field . '=' . $val;
if (empty($val) && $val !== 0) {
    echo 'UNKNOWN: Field ' . $field . ' not found' . PHP_EOL;
    exit(3);
}
if (array_key_exists('r', $options)) {
    $wantedResp = json_decode($options['r'], true);
    if ($val != $wantedResp) {
        echo 'CRITICAL: ' . $out_msg . PHP_EOL;
        exit(2);