2010-11-26 15:11:14 +01:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
#
|
|
|
|
# Description:
|
|
|
|
# This plugin shows basic filesystem information and statistics about the HDFS
|
|
|
|
# filesystem.
|
|
|
|
#
|
|
|
|
# Installation notes:
|
|
|
|
# Symlink this file to hadoop_hdfs_block or hadoop_hdfs_capacity to get block
|
|
|
|
# or capacity informations about the DFS.
|
|
|
|
#
|
2013-12-20 20:03:42 +01:00
|
|
|
#
|
|
|
|
# Needs following minimal configuration in plugin-conf.d/munin-node:
|
|
|
|
# [hadoop_hdfs_block]
|
|
|
|
# user hdfs
|
|
|
|
#
|
|
|
|
# [hadoop_hdfs_capacity]
|
|
|
|
# user hdfs
|
|
|
|
#
|
2010-11-26 15:11:14 +01:00
|
|
|
# Author: KARASZI Istvan <muninexchange@spam.raszi.hu>
|
|
|
|
#
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use File::Basename qw(basename);
|
2013-12-20 20:03:42 +01:00
|
|
|
use Munin::Plugin;
|
2010-11-26 15:11:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# main
|
|
|
|
#
|
2013-12-20 19:18:46 +01:00
|
|
|
my $type = &getType($0);
|
2010-11-26 15:11:14 +01:00
|
|
|
if ($ARGV[0]) {
|
|
|
|
if ($ARGV[0] eq "autoconf") {
|
|
|
|
print "yes\n";
|
|
|
|
} elsif ($ARGV[0] eq "config") {
|
|
|
|
&printConfig();
|
|
|
|
} else {
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
&getStatistics();
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# methods
|
|
|
|
#
|
|
|
|
sub getType {
|
|
|
|
my($command) = @_;
|
|
|
|
|
|
|
|
my $scriptname = &File::Basename::basename($command);
|
|
|
|
if ($scriptname =~ /_([^_]+)$/) {
|
|
|
|
if (grep($1, ('block', 'capacity'))) {
|
|
|
|
return $1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
die("Invalid command type '$scriptname'");
|
|
|
|
}
|
|
|
|
|
|
|
|
sub printConfig {
|
|
|
|
if ($type eq "block") {
|
|
|
|
print <<EOT;
|
|
|
|
graph_title DFS Statistics
|
2017-02-23 02:46:23 +01:00
|
|
|
graph_category fs
|
2010-11-26 15:11:14 +01:00
|
|
|
graph_vlabel count
|
|
|
|
block.label Under replicated blocks
|
|
|
|
corrupt.label Blocks with corrupt replicas
|
|
|
|
missing.label Missing blocks
|
|
|
|
EOT
|
|
|
|
} elsif ($type eq "capacity") {
|
|
|
|
print <<EOT;
|
|
|
|
graph_title DFS Capacity
|
2017-02-23 02:46:23 +01:00
|
|
|
graph_category fs
|
2010-11-26 15:11:14 +01:00
|
|
|
graph_vlabel capacity
|
|
|
|
configured.label Configured
|
|
|
|
present.label Present
|
|
|
|
remaining.label DFS Remaining
|
|
|
|
EOT
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub getBlock {
|
|
|
|
my($line) = @_;
|
|
|
|
|
|
|
|
if ($line =~ /^Under replicated blocks: (\d+)/) {
|
|
|
|
printf("block.value %d\n", $1);
|
|
|
|
} elsif ($line =~ /^Blocks with corrupt replicas: (\d+)/) {
|
|
|
|
printf("corrupt.value %d\n", $1);
|
|
|
|
} elsif ($line =~ /^Missing blocks: (\d+)/) {
|
|
|
|
printf("missing.value %d\n", $1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub getCapacity {
|
|
|
|
my($line) = @_;
|
|
|
|
|
|
|
|
if ($line =~ /^Configured Capacity: (\d+)/) {
|
|
|
|
printf("configured.value %d\n", $1);
|
|
|
|
} elsif ($line =~ /^Present Capacity: (\d+)/) {
|
|
|
|
printf("present.value %d\n", $1);
|
|
|
|
} elsif ($line =~ /^DFS Remaining: (\d+)/) {
|
2010-12-13 14:05:34 +01:00
|
|
|
printf("remaining.value %d\n", $1);
|
2010-11-26 15:11:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub getStatistics {
|
2013-12-20 20:03:42 +01:00
|
|
|
open(DFSADMIN, "hdfs dfsadmin -report|") || die("Cannot open dfsadmin: $!");
|
2010-11-26 15:11:14 +01:00
|
|
|
while(defined(my $line = <DFSADMIN>)) {
|
|
|
|
chomp($line);
|
2013-12-20 22:06:41 +01:00
|
|
|
if ($line =~ /-------------------------------------------------/) {
|
|
|
|
last
|
|
|
|
}
|
2010-11-26 15:11:14 +01:00
|
|
|
|
|
|
|
if ($type eq "block") {
|
|
|
|
&getBlock($line);
|
|
|
|
} elsif ($type eq "capacity") {
|
|
|
|
&getCapacity($line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(DFSADMIN)
|
|
|
|
}
|