forked from HariSekhon/Nagios-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_hadoop_yarn_apps_memory_used.pl
executable file
·92 lines (71 loc) · 2.29 KB
/
check_hadoop_yarn_apps_memory_used.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
#!/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
#
# License: see accompanying LICENSE file
#
$DESCRIPTION = "Nagios Plugin to check Hadoop Yarn app memory via Resource Manager jmx
Optional thresholds on % used memory to aid in capacity planning
Tested on Hortonworks HDP 2.1 (Hadoop 2.4.0.2.1.1.0-385)";
$VERSION = "0.3";
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';
$ua->agent("Hari Sekhon $progname version $main::VERSION");
set_port_default(8088);
env_creds(["HADOOP_YARN_RESOURCE_MANAGER", "HADOOP"], "Yarn Resource Manager");
%options = (
%hostoptions,
%thresholdoptions,
);
get_options();
$host = validate_host($host);
$port = validate_port($port);
validate_thresholds(0, 0, { "simple" => "upper", "positive" => 1, "integer" => 0, "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 Yarn Resource Manager at '$url'";
};
vlog3(Dumper($json));
my @beans = get_field_array("beans");
my $found_mbean = 0;
foreach(@beans){
next unless get_field2($_, "name") eq "Hadoop:service=ResourceManager,name=QueueMetrics,q0=root";
$found_mbean++;
my $available_mb = get_field2_float($_, "AvailableMB");
my $allocated_mb = get_field2_float($_, "AllocatedMB");
my $total_mb = $available_mb + $allocated_mb;
my $pc_used = sprintf("%.1f", $allocated_mb / $total_mb * 100);
$msg .= "$pc_used% yarn app memory used";
check_thresholds($pc_used);
if($verbose){
$msg .= " [${allocated_mb}MB/${total_mb}MB]";
} else {
$msg .= " [" . ( $allocated_mb ? human_units($allocated_mb*1024*1024) : 0 ) . "/" . human_units($total_mb*1024*1024) . "]";
}
$msg .= " | ";
$msg .= "'% Yarn App Memory Used'=${pc_used}%";
msg_perf_thresholds();
$msg .= "0;100; 'Allocated Yarn App Memory'=${allocated_mb}MB;;;0;${total_mb}MB";
last;
}
quit "UNKNOWN", "failed to find mbean. $nagios_plugins_support_msg_api" unless $found_mbean;
quit $status, $msg;