Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / other / hadoop-dfs-plugin @ 1e42e4a0

Historique | Voir | Annoter | Télécharger (2,12 ko)

1
#!/usr/bin/perl
2

    
3
#
4
# Description:
5
# This plugin shows basic filesystem information and statistics about the HDFS
6
# filesystem.
7
#
8
# Installation notes:
9
# Symlink this file to hadoop_hdfs_block or hadoop_hdfs_capacity to get block
10
# or capacity informations about the DFS.
11
#
12
# Author: KARASZI Istvan <muninexchange@spam.raszi.hu>
13
#
14

    
15
use strict;
16
use File::Basename qw(basename);
17

    
18
my $type = &getType($0);
19

    
20
#
21
# main
22
#
23
if ($ARGV[0]) {
24
	if ($ARGV[0] eq "autoconf") {
25
		print "yes\n";
26
	} elsif ($ARGV[0] eq "config") {
27
		&printConfig();
28
	} else {
29
		exit(1);
30
	}
31
} else {
32
	&getStatistics();
33
}
34

    
35
#
36
# methods
37
#
38
sub getType {
39
	my($command) = @_;
40

    
41
	my $scriptname = &File::Basename::basename($command);
42
	if ($scriptname =~ /_([^_]+)$/) {
43
		if (grep($1, ('block', 'capacity'))) {
44
			return $1;
45
		}
46
	}
47

    
48
	die("Invalid command type '$scriptname'");
49
}
50

    
51
sub printConfig {
52
	if ($type eq "block") {
53
		print <<EOT;
54
graph_title DFS Statistics
55
graph_category hadoop
56
graph_vlabel count
57
block.label Under replicated blocks
58
corrupt.label Blocks with corrupt replicas
59
missing.label Missing blocks
60
EOT
61
	} elsif ($type eq "capacity") {
62
		print <<EOT;
63
graph_title DFS Capacity
64
graph_category hadoop
65
graph_vlabel capacity
66
configured.label Configured
67
present.label Present
68
remaining.label DFS Remaining
69
EOT
70
	}
71
}
72

    
73
sub getBlock {
74
	my($line) = @_;
75

    
76
	if ($line =~ /^Under replicated blocks: (\d+)/) {
77
		printf("block.value %d\n", $1);
78
	} elsif ($line =~ /^Blocks with corrupt replicas: (\d+)/) {
79
		printf("corrupt.value %d\n", $1);
80
	} elsif ($line =~ /^Missing blocks: (\d+)/) {
81
		printf("missing.value %d\n", $1);
82
	}
83
}
84

    
85
sub getCapacity {
86
	my($line) = @_;
87

    
88
	if ($line =~ /^Configured Capacity: (\d+)/) {
89
		printf("configured.value %d\n", $1);
90
	} elsif ($line =~ /^Present Capacity: (\d+)/) {
91
		printf("present.value %d\n", $1);
92
	} elsif ($line =~ /^DFS Remaining: (\d+)/) {
93
		printf("remaining.value %d\n", $1);
94
	}
95
}
96

    
97
sub getStatistics {
98
	open(DFSADMIN, "hadoop dfsadmin -report|") || die("Cannot open dfsadmin: $!");
99
	while(defined(my $line = <DFSADMIN>)) {
100
		chomp($line);
101

    
102
		if ($type eq "block") {
103
			&getBlock($line);
104
		} elsif ($type eq "capacity") {
105
			&getCapacity($line);
106
		}
107
	}
108
	close(DFSADMIN)
109
}