forked from HariSekhon/Nagios-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_hadoop_hdfs_space.pl
executable file
·93 lines (74 loc) · 2.26 KB
/
check_hadoop_hdfs_space.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
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/perl -T
# nagios: -epn
#
# Author: Hari Sekhon
# Date: 2014-03-05 21:45:08 +0000 (Wed, 05 Mar 2014)
#
# http://github.com/harisekhon/nagios-plugins
#
# License: see accompanying LICENSE file
#
$DESCRIPTION = "Nagios Plugin to check Hadoop HDFS Space % used via NameNode JMX
See also check_hadoop_dfs.pl for an older implementation that parses dfsadmin output.
Tested on Hortonworks HDP 2.1 (Hadoop 2.4.0.2.1.1.0-385)";
$VERSION = "0.1";
use strict;
use warnings;
BEGIN {
use File::Basename;
use lib dirname(__FILE__) . "/lib";
}
use HariSekhonUtils;
use Data::Dumper;
use JSON::XS;
use LWP::Simple '$ua';
use POSIX 'floor';
$ua->agent("Hari Sekhon $progname version $main::VERSION");
set_port_default(50070);
set_threshold_defaults(80, 90);
env_creds(["HADOOP_NAMENODE", "HADOOP"], "Hadoop NameNode");
%options = (
%hostoptions,
%thresholdoptions,
);
get_options();
$host = validate_host($host);
$port = validate_port($port);
validate_thresholds(1, 1, { "simple" => "upper", "positive" => 1, "integer" => 1, "min" => 0, "max" => 100});
vlog2;
set_timeout();
$status = "OK";
my $url = "http://$host:$port/jmx";
my $content = curl $url;
try{
$json = decode_json $content;
};
catch{
quit "invalid json returned by NameNode at '$url'";
};
vlog3(Dumper($json));
my @beans = get_field_array("beans");
my $found_mbean = 0;
my $pc_used;
my $files;
my $blocks;
my $used;
my $total;
foreach(@beans){
next unless get_field2($_, "name") eq "Hadoop:service=NameNode,name=NameNodeInfo";
$found_mbean = 1;
$pc_used = get_field2_float($_, "PercentUsed");
$files = get_field2_int($_, "TotalFiles");
$blocks = get_field2_int($_, "TotalBlocks");
$used = get_field2_int($_, "Used");
$total = get_field2_int($_, "Total");
last;
}
quit "UNKNOWN", "failed to find namenode NameNodeInfo mbean" unless $found_mbean;
$msg .= sprintf("%.1f%% HDFS used", $pc_used);
check_thresholds($pc_used);
$msg .= sprintf(" (%s/%s), in %d files spread across %s blocks", human_units($used), human_units($total), $files, $blocks);
$msg .= sprintf(" | 'HDFS %% space used'=%f%%", $pc_used);
msg_perf_thresholds();
$msg .= sprintf(" 'HDFS space used'=%db 'HDFS file count'=%d 'HDFS block count'=%d", $used, $files, $blocks);
quit $status, $msg;