forked from HariSekhon/Nagios-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_hadoop_datanode_blockcount.pl
executable file
·73 lines (55 loc) · 2 KB
/
check_hadoop_datanode_blockcount.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
#!/usr/bin/perl -T
# nagios: -epn
#
# Author: Hari Sekhon
# Date: 2013-10-29 01:01:21 +0000 (Tue, 29 Oct 2013)
#
# http://github.com/harisekhon
#
# License: see accompanying LICENSE file
#
$DESCRIPTION = "Nagios Plugin to check the number of blocks on a Hadoop HDFS Datanode via it's blockScannerReport";
$VERSION = "0.3";
use strict;
use warnings;
BEGIN {
use File::Basename;
use lib dirname(__FILE__) . "/lib";
}
use HariSekhonUtils;
use LWP::Simple '$ua';
my $default_port = 50075;
$port = $default_port;
# This is based on experience, real clusters seem to run in to problems after 300,000 blocks per DN. Cloudera Manager also alerts around thsi point
my $default_warning = 300000;
my $default_critical = 500000;
$warning = $default_warning;
$critical = $default_critical;
%options = (
"H|host=s" => [ \$host, "DataNode host to connect to" ],
"P|port=s" => [ \$port, "DataNode HTTP port (default: $default_port)" ],
"w|warning=s" => [ \$warning, "Warning threshold or ran:ge (inclusive, default: $default_warning)" ],
"c|critical=s" => [ \$critical, "Critical threshold or ran:ge (inclusive, default: $default_critical)" ],
);
@usage_order = qw/host port warning critical/;
get_options();
$host = validate_host($host);
$port = validate_port($port);
validate_thresholds(undef, undef, { "simple" => "upper", "integer" => 1, "positive" => 1});
vlog2;
set_timeout();
set_http_timeout($timeout - 1);
$status = "OK";
$ua->agent("Hari Sekhon $progname $main::VERSION");
my $blockScannerReport = curl "http://$host:$port/blockScannerReport", "datanode $host";
my $block_count;
if($blockScannerReport =~ /Total Blocks\s+:\s+(\d+)/){
$block_count = $1;
} else {
quit "CRITICAL", "failed to find total block count from blockScannerReport, $nagios_plugins_support_msg";
}
$msg = "$block_count blocks on datanode $host";
check_thresholds($block_count);
$msg .= " | block_count=$block_count";
msg_perf_thresholds();
quit $status, $msg;