forked from HariSekhon/Nagios-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_hadoop_jobtracker.pl
executable file
·282 lines (252 loc) · 13.1 KB
/
check_hadoop_jobtracker.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#!/usr/bin/perl -T
# nagios: -epn
#
# Author: Hari Sekhon
# Date: 2012-10-05 14:00:09 +0100 (Fri, 05 Oct 2012)
#
# http://github.com/harisekhon/nagios-plugins
#
# License: see accompanying LICENSE file
#
# TODO: switch this to use /jmx as /metrics doesn't expose non-heap max
$DESCRIPTION = "Nagios Plugin to run various checks against a Hadoop MapReduce cluster by querying the JobTracker
This is a consolidation/rewrite of two of my previous plugins for MapReduce cluster checks
Runs in 1 of 3 modes:
1. available MapReduce nodes and detect any Blacklisted nodes
- any Blacklisted nodes raises Critical
- checks optional thresholds for the minimum number of available MapReduce nodes available (default 0 == disabled)
2. detect which MapReduce nodes aren't active in the JobTracker if given a node list
- checks optional thresholds for the maximum number of missing nodes from the specified list (default 0 == CRITICAL on any missing, you may want to set these thresholds higher)
3. checks the JobTracker Heap % Used
Originally written on old vanilla Apache Hadoop 0.20.x, backwards untested rewrite for CDH 4.3 (2.0.0-mr1-cdh4.3.0)
Seriously recommend you consider using check_hadoop_cloudera_manager_metrics.pl instead if possible (disclaimer I work for Cloudera but seriously it's better it uses the CM API instead of scraping output which can break betweens versions and requires more maintenance)";
$VERSION = "0.9.3";
use strict;
use warnings;
BEGIN {
use File::Basename;
use lib dirname(__FILE__) . "/lib";
}
use HariSekhonUtils qw/:DEFAULT :regex/;
use LWP::Simple '$ua';
$ua->agent("Hari Sekhon $progname version $main::VERSION");
# this is really just for constraining the size of the output printed
my $MAX_NODES_TO_DISPLAY_AS_ACTIVE = 5;
my $MAX_NODES_TO_DISPLAY_AS_MISSING = 30;
my $nodes;
my $heap;
my $non_heap;
# originally scraped the HTML in Apache 0.20.x, instead using metrics page now as it's clearner
#my $jobtracker_urn = "jobtracker.jsp";
my $jobtracker_urn = "metrics";
my $jobtracker_urn_machines_active = "machines.jsp?type=active";
set_port_default(50030);
my $default_warning = 0;
my $default_critical = 0;
$warning = $default_warning;
$critical = $default_critical;
env_creds(["HADOOP_JOBTRACKER", "HADOOP"], "Hadoop JobTracker");
%options = (
%hostoptions,
"n|nodes=s" => [ \$nodes, "Optional list of nodes to check are alive in the JobTracker (non-switch args are appended to this list for convenience)" ],
"heap-usage" => [ \$heap, "Check JobTracker Heap % Used. There is a bug in the JobTracker UI where it's showing committed instead of used so after some run time it always appears full" ],
#"non-heap-usage" => [ \$non_heap, "Check JobTracker Non Heap % Used. Optional % thresholds may be supplied for warning/critical" ],
"w|warning=s" => [ \$warning, "Warning threshold or ran:ge (inclusive) for min number of available nodes or max missing/inactive nodes if node list is given (defaults to $default_warning)" ],
"c|critical=s" => [ \$critical, "Critical threshold or ran:ge (inclusive) for min number of available nodes or max missing/inactive nodes if node list is given (defaults to $default_critical)" ],
);
@usage_order = qw/host port nodes heap-usage non-heap-usage warning critical/;
get_options();
defined($host) or usage "JobTracker host not specified";
if($progname eq "check_hadoop_mapreduce_nodes_active.pl"){
defined($nodes) or usage "Node list not specified";
}
if($nodes and ($heap or $non_heap)){
usage "Cannot specify both --nodes and --[non-]heap-usage";
}
$host = isHost($host) || usage "JobTracker host invalid, must be hostname/FQDN or IP address";
vlog_options "host", "'$host'";
$host = validate_resolvable($host);
$port = validate_port($port);
my $url;
my %nodes;
my @nodes;
my %stats;
if(defined($nodes)){
$url = "http://$host:$port/$jobtracker_urn_machines_active";
# this uniqs the list of nodes given
%nodes = map { $_ => 1 } split(/[,\s]+/, $nodes);
@nodes = sort keys %nodes;
push(@nodes, @ARGV);
scalar @nodes or usage "node list empty";
foreach my $node (@nodes){
$node = isHost($node) || usage "Node name '$node' invalid, must be hostname/FQDN or IP address";
}
vlog2 "nodes: '" . join(",", @nodes) . "'";
validate_thresholds(undef, undef, {
"positive" => 1,
"integer" => 1
} );
} elsif($heap or $non_heap){
$url = "http://$host:$port/$jobtracker_urn";
validate_thresholds(1, 1, {
"simple" => "upper",
"positive" => 1,
"integer" => 0,
"max" => 100
});
} else {
$url = "http://$host:$port/$jobtracker_urn";
validate_thresholds(undef, undef, {
"simple" => "lower",
"positive" => 1,
"integer" => 1
});
}
vlog2;
set_timeout();
set_http_timeout($timeout - 1);
my $content = curl $url, "JobTracker";
# Note: This was created for Apache Hadoop 0.20.2, r911707. If they change this page across versions, this plugin will need to be updated
vlog2 "parsing output from JobTracker\n";
my @stats;
sub check_stats_parsed(){
foreach(@stats){
unless(defined($stats{$_})){
vlog2;
quit "UNKNOWN", "failed to find $_ in JobTracker output";
}
vlog2 "stats $_ = $stats{$_}";
}
vlog2;
}
sub parse_stats(){
foreach my $line (split("\n", $content)){
foreach my $stat (@stats){
if($line =~ /^\s*$stat\s*=\s*(\d+(?:\.\d+)?)\s*$/){
$stats{$stat} = $1;
last;
}
}
}
check_stats_parsed();
}
if(defined($nodes)){
my @missing_nodes;
foreach my $node (@nodes){
unless($content =~ /<td>$node(?:\.$domain_regex)?<\/td>/){
push(@missing_nodes, $node);
}
}
$nodes = scalar @nodes;
plural($nodes);
my $missing_nodes = scalar @missing_nodes;
$status = "OK";
if($missing_nodes){
if($missing_nodes <= $MAX_NODES_TO_DISPLAY_AS_MISSING){
$msg = "'" . join(",", sort @missing_nodes) . "'";
} else {
$msg = "$missing_nodes/$nodes node$plural";
}
$msg .= " not";
} else {
if($nodes <= $MAX_NODES_TO_DISPLAY_AS_ACTIVE){
$msg = "'" . join(",", sort @nodes) . "'";
} else {
$msg = "$nodes/$nodes checked node$plural";
}
}
$msg .= " found in the active machines list on the JobTracker" . ($verbose ? " at '$host:$port'" : "");
if($verbose){
if($missing_nodes and $missing_nodes <= $MAX_NODES_TO_DISPLAY_AS_MISSING){
$msg .= " ($missing_nodes/$nodes checked node$plural)";
} elsif ($nodes <= $MAX_NODES_TO_DISPLAY_AS_ACTIVE){
$msg .= " ($nodes/$nodes checked node$plural)";
}
}
check_thresholds($missing_nodes);
} elsif($heap or $non_heap){
# foreach(split("\n", $content)){
# if(/Cluster Summary \(Heap Size is (\d+(?:\.\d+)?) (.B)\/(\d+(?:\.\d+)?) (.B)\)/i){
# $stats{"heap_used"} = $1;
# $stats{"heap_used_units"} = $2;
# $stats{"heap_max"} = $3;
# $stats{"heap_max_units"} = $4;
# $stats{"heap_used_bytes"} = expand_units($stats{"heap_used"}, $stats{"heap_used_units"}, "Heap Used");
# $stats{"heap_max_bytes"} = expand_units($stats{"heap_max"}, $stats{"heap_max_units"}, "Heap Max" );
# $stats{"heap_used_pc"} = sprintf("%.2f", $stats{"heap_used_bytes"} / $stats{"heap_max_bytes"} * 100);
# last;
# }
# }
# foreach(qw/heap_used heap_used_units heap_max heap_max_units heap_used_bytes heap_max_bytes heap_used_pc/){
my $heap_str;
if($heap){
$heap_str = "Heap";
@stats = qw/memHeapUsedM maxMemoryM/;
} elsif($non_heap){
$heap_str = "Non Heap";
@stats = qw/memNonHeapUsedM maxNonMemoryM/; #max non heap memory isn't exposed in /metrics, switch to /jmx
} else {
code_error "failed to determine heap vs non-heap late in code";
}
parse_stats();
#$stats{"heap_used_pc"} = $stats{"memHeapUsedM"} / $stats{"maxMemoryM"} * 100;
$stats{"${heap_str}_used_pc"} = $stats{$stats[0]} / $stats{$stats[1]} * 100;
$status = "OK";
#$msg = sprintf("JobTracker Heap %.2f%% Used (%s %s used, %s %s total)", $stats{"heap_used_pc"}, $stats{"heap_used"}, $stats{"heap_used_units"}, $stats{"heap_max"}, $stats{"heap_max_units"});
$msg = sprintf("JobTracker $heap_str %.2f%% Used (%s MB used, %s MB total)", $stats{"${heap_str}_used_pc"}, $stats{$stats[0]}, $stats{$stats[1]});
check_thresholds($stats{"${heap_str}_used_pc"});
#$msg .= " | 'JobTracker Heap % Used'=$stats{heap_used_pc}%;" . ($thresholds{warning}{upper} ? $thresholds{warning}{upper} : "" ) . ";" . ($thresholds{critical}{upper} ? $thresholds{critical}{upper} : "" ) . ";0;100 'JobTracker Heap Used'=$stats{heap_used_bytes}B";
$msg .= " | 'JobTracker $heap_str % Used'=" . $stats{"${heap_str}_used_pc"} . "%" . msg_perf_thresholds(1) . "0;100 'JobTracker $heap_str Used'=$stats{$stats[0]}MB";
} else {
# Old Apache 0.20.x
#if($content =~ /<tr><th>Maps<\/th><th>Reduces<\/th><th>Total Submissions<\/th><th>Nodes<\/th><th>Map Task Capacity<\/th><th>Reduce Task Capacity<\/th><th>Avg\. Tasks\/Node<\/th><th>Blacklisted Nodes<\/th><\/tr>\n<tr><td>(\d+)<\/td><td>(\d+)<\/td><td>(\d+)<\/td><td><a href="machines\.jsp\?type=active">(\d+)<\/a><\/td><td>(\d+)<\/td><td>(\d+)<\/td><td>(\d+(?:\.\d+)?)<\/td><td><a href="machines\.jsp\?type=blacklisted">(\d+)<\/a><\/td><\/tr>/mi or
# $stats{"maps"} = $1;
# $stats{"reduces"} = $2;
# $stats{"total_submissions"} = $3;
# $stats{"nodes"} = $4;
# $stats{"map_task_capacity"} = $5;
# $stats{"reduce_task_capacity"} = $6;
# $stats{"avg_tasks_node"} = $7;
# $stats{"blacklisted_nodes"} = $8;
# Apache 2.0.x MR1 from CDH 4.3, unfinished, switch to /metrics instead
# $content =~ /<tr><th>Running Map Tasks<\/th><th>Running Reduce Tasks<\/th><th>Total Submissions<\/th><th>Nodes<\/th><th>Occupied Map Slots<\/th><th>Occupied Reduce Slots<\/th><th>Reserved Map Slots<\/th><th>Reserved Reduce Slots<\/th><th>Map Task Capacity<\/th><th>Reduce Task Capacity<\/th><th>Avg. Tasks\/Node<\/th><th>Blacklisted Nodes<\/th><th>Excluded Nodes<\/th><\/tr>
#<tr><td>(\d+)<\/td><td>(\d+)<\/td><td>(\d+)<\/td><td><a href="machines\.jsp?type=active">(\d+)<\/a><\/td><td>\d+<\/td><td>\d+<\/td><td>\d+<\/td><td>\d+<\/td><td>(\d+)<\/td><td>(\d+)<\/td><td>(\d+(?:\.\d+)?)<\/td><td><a href="machines.jsp?type=blacklisted">(\d+)<\/a><\/td><td><a href="machines.jsp?type=excluded">\d+<\/a><\/td><\/tr>/mi){
# my $stats_map = (
# "maps" => "running_maps",
# "reduces" => "running_reduces",
# "total_submissions" => "jobs_submitted",
# "nodes" => "trackers",
# "map_task_capacity" => "map_slots"
# "reduce_task_capacity" => "reduce_slots",
# # not supplied in /metrics
# #"avg_tasks_node" =>
# "blacklisted_nodes" => "trackers_blacklisted",
# );
@stats = qw/jobs_submitted map_slots reduce_slots running_maps running_reduces trackers trackers_blacklisted/;
parse_stats();
#foreach(qw/maps reduces total_submissions nodes map_task_capacity reduce_task_capacity avg_tasks_node blacklisted_nodes/){
$stats{"avg_tasks_node"} = ($stats{"map_slots"} + $stats{"reduce_slots"}) / $stats{"trackers"};
$status = "OK";
#$msg = sprintf("%d MapReduce nodes available, %d blacklisted nodes", $stats{"nodes"}, $stats{"blacklisted_nodes"});
$msg = sprintf("%d MapReduce nodes available, %d blacklisted nodes", $stats{"trackers"}, $stats{"trackers_blacklisted"});
$thresholds{"warning"}{"lower"} = 0 unless $thresholds{"warning"}{"lower"};
$thresholds{"critical"}{"lower"} = 0 unless $thresholds{"critical"}{"lower"};
check_thresholds($stats{"trackers"});
# TODO: This requires a pnp4nagios config for Maps and Tasks which are basically counters
$msg .= sprintf(" | 'MapReduce Nodes'=%d;%d;%d 'Blacklisted Nodes'=%d Maps=%d Reduces=%d 'Total Submissions'=%d 'Map Task Capacity'=%d 'Reduce Task Capacity'=%d 'Avg. Tasks/Node'=%.2f",
$stats{"trackers"},
$thresholds{"warning"}{"lower"},
$thresholds{"critical"}{"lower"},
$stats{"trackers_blacklisted"},
$stats{"running_maps"},
$stats{"running_reduces"},
$stats{"jobs_submitted"},
$stats{"map_slots"},
$stats{"reduce_slots"},
$stats{"avg_tasks_node"}
);
if($stats{"trackers_blacklisted"}){
critical;
}
}
quit $status, $msg;