Projet

Général

Profil

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

root / plugins / hdfs / hadoop-dfs-plugin @ 4e69103a

Historique | Voir | Annoter | Télécharger (2,39 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 information about the DFS.
11
#
12
#
13
# Needs following minimal configuration in plugin-conf.d/munin-node:
14
# [hadoop_hdfs_block]
15
# user hdfs
16
#
17
# [hadoop_hdfs_capacity]
18
# user hdfs
19
#
20
# Author: KARASZI István <muninexchange@spam.raszi.hu>
21
#
22

    
23
use strict;
24
use File::Basename qw(basename);
25
use Munin::Plugin;
26

    
27

    
28
#
29
# main
30
#
31
my $type = &getType($0);
32
if ($ARGV[0]) {
33
	if ($ARGV[0] eq "autoconf") {
34
		print "yes\n";
35
	} elsif ($ARGV[0] eq "config") {
36
		&printConfig();
37
	} else {
38
		exit(1);
39
	}
40
} else {
41
	&getStatistics();
42
}
43

    
44
#
45
# methods
46
#
47
sub getType {
48
	my($command) = @_;
49

    
50
	my $scriptname = &File::Basename::basename($command);
51
	if ($scriptname =~ /_([^_]+)$/) {
52
		if (grep($1, ('block', 'capacity'))) {
53
			return $1;
54
		}
55
	}
56

    
57
	die("Invalid command type '$scriptname'");
58
}
59

    
60
sub printConfig {
61
	if ($type eq "block") {
62
		print <<EOT;
63
graph_title DFS Statistics
64
graph_category fs
65
graph_vlabel count
66
block.label Under replicated blocks
67
corrupt.label Blocks with corrupt replicas
68
missing.label Missing blocks
69
EOT
70
	} elsif ($type eq "capacity") {
71
		print <<EOT;
72
graph_title DFS Capacity
73
graph_category fs
74
graph_vlabel capacity
75
configured.label Configured
76
present.label Present
77
remaining.label DFS Remaining
78
EOT
79
	}
80
}
81

    
82
sub getBlock {
83
	my($line) = @_;
84

    
85
	if ($line =~ /^Under replicated blocks: (\d+)/) {
86
		printf("block.value %d\n", $1);
87
	} elsif ($line =~ /^Blocks with corrupt replicas: (\d+)/) {
88
		printf("corrupt.value %d\n", $1);
89
	} elsif ($line =~ /^Missing blocks: (\d+)/) {
90
		printf("missing.value %d\n", $1);
91
	}
92
}
93

    
94
sub getCapacity {
95
	my($line) = @_;
96

    
97
	if ($line =~ /^Configured Capacity: (\d+)/) {
98
		printf("configured.value %d\n", $1);
99
	} elsif ($line =~ /^Present Capacity: (\d+)/) {
100
		printf("present.value %d\n", $1);
101
	} elsif ($line =~ /^DFS Remaining: (\d+)/) {
102
		printf("remaining.value %d\n", $1);
103
	}
104
}
105

    
106
sub getStatistics {
107
	open(DFSADMIN, "hdfs dfsadmin -report|") || die("Cannot open dfsadmin: $!");
108
	while(defined(my $line = <DFSADMIN>)) {
109
		chomp($line);
110
                if ($line =~ /-------------------------------------------------/) {
111
                   last
112
                }
113

    
114
		if ($type eq "block") {
115
			&getBlock($line);
116
		} elsif ($type eq "capacity") {
117
			&getCapacity($line);
118
		}
119
	}
120
	close(DFSADMIN)
121
}