hadoop-metrics 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
data/lib/hadoop_metrics.rb
CHANGED
@@ -1,2 +1,3 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "hadoop_metrics/job_tracker"
|
2
|
+
require "hadoop_metrics/task_tracker"
|
3
|
+
require "hadoop_metrics/name_node"
|
data/lib/hadoop_metrics/api.rb
CHANGED
@@ -6,14 +6,20 @@ module HadoopMetrics
|
|
6
6
|
def initialize(host, port, opts = {})
|
7
7
|
@endpoint = "#{host}:#{port}"
|
8
8
|
@metrics_endpoint = URI("http://#{@endpoint}/metrics?format=json")
|
9
|
-
@snake_case = opts[:snake_case]
|
9
|
+
@snake_case = opts.has_key?(:snake_case) ? opts[:snake_case] : true
|
10
10
|
@name = opts[:name] || host
|
11
|
+
@metrics_cache = nil
|
11
12
|
end
|
12
13
|
|
13
14
|
attr_reader :name
|
14
15
|
|
15
|
-
def metrics
|
16
|
-
|
16
|
+
def metrics(force = true)
|
17
|
+
if !@metrics_cache.nil? and !force
|
18
|
+
return @metrics_cache
|
19
|
+
end
|
20
|
+
|
21
|
+
@metrics_cache = HadoopMetrics.get_response(@metrics_endpoint)
|
22
|
+
@metrics_cache
|
17
23
|
end
|
18
24
|
|
19
25
|
def gc
|
@@ -44,8 +50,12 @@ module HadoopMetrics
|
|
44
50
|
|
45
51
|
private
|
46
52
|
|
47
|
-
def
|
48
|
-
|
53
|
+
def get_force(opts)
|
54
|
+
opts.has_key?(:force) ? opts[:force] : true
|
55
|
+
end
|
56
|
+
|
57
|
+
def group_by(category, target, column, force)
|
58
|
+
categories = metrics(force)[category]
|
49
59
|
return nil if categories.nil?
|
50
60
|
|
51
61
|
targets = categories[target]
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "hadoop_metrics/api"
|
2
2
|
|
3
3
|
module HadoopMetrics
|
4
4
|
class JobTracker
|
@@ -10,19 +10,27 @@ module HadoopMetrics
|
|
10
10
|
via_jmx('hadoop:service=JobTracker,name=JobTrackerInfo', JSON_FILED_VALUES).first
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
|
13
|
+
def mapred(opts = {})
|
14
|
+
disable_snake_case {
|
15
|
+
group_by('mapred', 'jobtracker', 'hostName', get_force(opts)).each_pair { |k, v|
|
16
|
+
return v.first
|
17
|
+
}
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def fairscheduler_pools(opts = {})
|
22
|
+
group_by('fairscheduler', 'pools', get_column(opts), get_force(opts))
|
15
23
|
end
|
16
24
|
|
17
|
-
def fairscheduler_jobs(
|
18
|
-
group_by('fairscheduler','jobs',
|
25
|
+
def fairscheduler_jobs(opts = {})
|
26
|
+
group_by('fairscheduler','jobs', get_column(opts), get_force(opts))
|
19
27
|
end
|
20
28
|
|
21
|
-
def fairscheduler_running_tasks(
|
22
|
-
fs = metrics['fairscheduler']
|
29
|
+
def fairscheduler_running_tasks(opts = {})
|
30
|
+
fs = metrics(get_force(opts))['fairscheduler']
|
23
31
|
return nil if fs.nil?
|
24
32
|
|
25
|
-
targets = fs[
|
33
|
+
targets = fs[get_target(opts)]
|
26
34
|
return nil if targets.nil?
|
27
35
|
|
28
36
|
each_tasks = {}
|
@@ -33,5 +41,15 @@ module HadoopMetrics
|
|
33
41
|
}
|
34
42
|
each_tasks
|
35
43
|
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def get_column(opts)
|
48
|
+
opts[:column] || 'name'
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_target(opts)
|
52
|
+
opts[:target] || 'pools'
|
53
|
+
end
|
36
54
|
end
|
37
55
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "hadoop_metrics/api"
|
2
|
+
|
3
|
+
module HadoopMetrics
|
4
|
+
class NameNode
|
5
|
+
include API
|
6
|
+
|
7
|
+
JSON_FILED_VALUES = %W(LiveNodes DeadNodes DecomNodes NameDirStatuses)
|
8
|
+
|
9
|
+
def info
|
10
|
+
via_jmx('Hadoop:service=NameNode,name=NameNodeInfo', JSON_FILED_VALUES).first
|
11
|
+
end
|
12
|
+
|
13
|
+
def dfs
|
14
|
+
via_jmx('Hadoop:service=NameNode,name=FSNamesystem').first
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "hadoop_metrics/api"
|
2
2
|
|
3
3
|
module HadoopMetrics
|
4
4
|
class TaskTracker
|
@@ -10,14 +10,22 @@ module HadoopMetrics
|
|
10
10
|
via_jmx('hadoop:service=TaskTracker,name=TaskTrackerInfo', JSON_FILED_VALUES).first
|
11
11
|
end
|
12
12
|
|
13
|
-
def shuffle_output(
|
13
|
+
def shuffle_output(opts = {})
|
14
|
+
column = get_column(opts)
|
14
15
|
column = HadoopMetrics.to_snake_case(column) if @snake_case
|
15
|
-
group_by('mapred', 'shuffleOutput', column)
|
16
|
+
group_by('mapred', 'shuffleOutput', column, get_force(opts))
|
16
17
|
end
|
17
18
|
|
18
|
-
def mapred(
|
19
|
+
def mapred(opts = {})
|
20
|
+
column = get_column(opts)
|
19
21
|
column = HadoopMetrics.to_snake_case(column) if @snake_case
|
20
|
-
group_by('mapred', 'tasktracker', column)
|
22
|
+
group_by('mapred', 'tasktracker', column, get_force(opts))
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def get_column(opts)
|
28
|
+
opts[:column] || 'sessionId'
|
21
29
|
end
|
22
30
|
end
|
23
31
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hadoop-metrics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -42,6 +42,7 @@ files:
|
|
42
42
|
- lib/hadoop_metrics.rb
|
43
43
|
- lib/hadoop_metrics/api.rb
|
44
44
|
- lib/hadoop_metrics/job_tracker.rb
|
45
|
+
- lib/hadoop_metrics/name_node.rb
|
45
46
|
- lib/hadoop_metrics/task_tracker.rb
|
46
47
|
- lib/hadoop_metrics/version.rb
|
47
48
|
homepage: https://github.com/repeatedly/hadoop-metrics
|
@@ -58,7 +59,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
58
59
|
version: '0'
|
59
60
|
segments:
|
60
61
|
- 0
|
61
|
-
hash: -
|
62
|
+
hash: -2921215695546108603
|
62
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
64
|
none: false
|
64
65
|
requirements:
|
@@ -67,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
68
|
version: '0'
|
68
69
|
segments:
|
69
70
|
- 0
|
70
|
-
hash: -
|
71
|
+
hash: -2921215695546108603
|
71
72
|
requirements: []
|
72
73
|
rubyforge_project:
|
73
74
|
rubygems_version: 1.8.23
|