forked from HariSekhon/Nagios-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_hadoop_yarn_app_stats.pl
executable file
·93 lines (73 loc) · 2 KB
/
check_hadoop_yarn_app_stats.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
#
# License: see accompanying LICENSE file
#
$DESCRIPTION = "Nagios Plugin to check Hadoop Yarn app stats via the Resource Manager's REST API
Optional thresholds are applied to the number of running apps on the cluster.
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';
$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 });
vlog2;
set_timeout();
$status = "OK";
my $url = "http://$host:$port/ws/v1/cluster/appstatistics";
my $content = curl $url;
try{
$json = decode_json $content;
};
catch{
quit "invalid json returned by Yarn Resource Manager at '$url'";
};
vlog3(Dumper($json));
$msg = "app stats: ";
my @stats = get_field_array("appStatInfo.statItem");
my %stats;
foreach (@stats){
$stats{get_field2($_, "state")} = get_field2($_, "count");
}
$msg = "yarn apps stats for cluster: ";
my $msg2;
my $state;
foreach(qw/RUNNING NEW NEW_SAVING SUBMITTED ACCEPTED FAILED KILLED FINISHED/){
$state = lc($_);
$msg .= "$state = $stats{$_}";
if($state eq "running"){
check_thresholds($stats{$_});
}
$msg .= ", ";
$msg2 .= sprintf("'%s'=%d%s", $state, $stats{$_},
(grep({ $state eq $_ } qw/new new_saving running submitted/) ? "" : "c") );
if($state eq "running"){
$msg2 .= msg_perf_thresholds(1);
}
$msg2 .= " ";
}
$msg =~ s/, $//;
$msg .= " | $msg2";
quit $status, $msg;