hadoop-metrics 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,22 +3,45 @@ require 'json'
3
3
 
4
4
  module HadoopMetrics
5
5
  module API
6
- def jmx
7
- jmx_json = HadoopMetrics.get_response(@jmx_endpoint)['beans'].first
8
- @json_value_fields.each { |f|
9
- jmx_json[f] = JSON.parse(jmx_json[f])
10
- }
11
- if @snake_case
12
- jmx_json = HadoopMetrics.snake_cased(jmx_json)
13
- end
14
-
15
- jmx_json
6
+ def initialize(host, port, opts = {})
7
+ @endpoint = "#{host}:#{port}"
8
+ @metrics_endpoint = URI("http://#{@endpoint}/metrics?format=json")
9
+ @snake_case = opts[:snake_case] || true
10
+ @name = opts[:name] || host
16
11
  end
17
12
 
13
+ attr_reader :name
14
+
18
15
  def metrics
19
16
  HadoopMetrics.get_response(@metrics_endpoint)
20
17
  end
21
18
 
19
+ def gc
20
+ disable_snake_case {
21
+ result = via_jmx('java.lang:type=GarbageCollector,name=*').map { |jmx_gc_info|
22
+ gc_info = {'type' => (/PS Scavenge/.match(jmx_gc_info['name']) ? 'minor' : 'major')}
23
+ gc_info['estimated_time'] = jmx_gc_info['CollectionTime']
24
+ gc_info['count'] = jmx_gc_info['CollectionCount']
25
+ gc_info['last_start'] = jmx_gc_info['LastGcInfo']['startTime']
26
+ gc_info['last_duration'] = jmx_gc_info['LastGcInfo']['duration']
27
+ gc_info
28
+ }
29
+ }
30
+ end
31
+
32
+ def via_jmx(query, json_fields = [])
33
+ HadoopMetrics.get_response(URI("http://#{@endpoint}/jmx?qry=#{query}"))['beans'].map { |jmx_json|
34
+ json_fields.each { |f|
35
+ jmx_json[f] = JSON.parse(jmx_json[f])
36
+ }
37
+ if @snake_case
38
+ jmx_json = HadoopMetrics.snake_cased(jmx_json)
39
+ end
40
+
41
+ jmx_json
42
+ }
43
+ end
44
+
22
45
  private
23
46
 
24
47
  def group_by(category, target, column)
@@ -35,6 +58,15 @@ module HadoopMetrics
35
58
  }
36
59
  end
37
60
 
61
+ def disable_snake_case
62
+ old_snake_case = @snake_case
63
+ @snake_case = false
64
+
65
+ yield
66
+ ensure
67
+ @snake_case = old_snake_case
68
+ end
69
+
38
70
  def method_missing(method, *args)
39
71
  category, target = method.to_s.split('_', 2)
40
72
  group_by(category, target, *args)
@@ -62,10 +94,14 @@ module HadoopMetrics
62
94
  end
63
95
 
64
96
  def self.snake_cased(json)
65
- snake_cased = {}
66
- json.each_pair { |k, v|
67
- snake_cased[HadoopMetrics.to_snake_case(k.dup)] = json[k]
97
+ snake_cased_json = {}
98
+ json.each_pair { |key, value|
99
+ v = json[key]
100
+ if v.is_a?(Hash)
101
+ v = snake_cased(v)
102
+ end
103
+ snake_cased_json[HadoopMetrics.to_snake_case(key.dup)] = v
68
104
  }
69
- snake_cased
105
+ snake_cased_json
70
106
  end
71
107
  end
@@ -4,11 +4,10 @@ module HadoopMetrics
4
4
  class JobTracker
5
5
  include API
6
6
 
7
- def initialize(host, port, opts = {})
8
- @jmx_endpoint = URI("http://#{host}:#{port}/jmx?qry=hadoop:service=JobTracker,name=JobTrackerInfo")
9
- @metrics_endpoint = URI("http://#{host}:#{port}/metrics?format=json")
10
- @json_value_fields = %W(SummaryJson AliveNodesInfoJson BlacklistedNodesInfoJson QueueInfoJson)
11
- @snake_case = opts.has_key?(:snake_case) ? opts[:snake_case] : true
7
+ JSON_FILED_VALUES = %W(SummaryJson AliveNodesInfoJson BlacklistedNodesInfoJson QueueInfoJson)
8
+
9
+ def info
10
+ via_jmx('hadoop:service=JobTracker,name=JobTrackerInfo', JSON_FILED_VALUES).first
12
11
  end
13
12
 
14
13
  def fairscheduler_pools(column = 'name')
@@ -4,11 +4,10 @@ module HadoopMetrics
4
4
  class TaskTracker
5
5
  include API
6
6
 
7
- def initialize(host, port, opts = {})
8
- @jmx_endpoint = URI("http://#{host}:#{port}/jmx?qry=hadoop:service=TaskTracker,name=TaskTrackerInfo")
9
- @metrics_endpoint = URI("http://#{host}:#{port}/metrics?format=json")
10
- @json_value_fields = %W(TasksInfoJson)
11
- @snake_case = opts[:snake_case] || true
7
+ JSON_FILED_VALUES = %W(TasksInfoJson)
8
+
9
+ def info
10
+ via_jmx('hadoop:service=TaskTracker,name=TaskTrackerInfo', JSON_FILED_VALUES).first
12
11
  end
13
12
 
14
13
  def shuffle_output(column = 'sessionId')
@@ -1,3 +1,3 @@
1
1
  module HadoopMetrics
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  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.1
4
+ version: 0.1.2
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-04-25 00:00:00.000000000 Z
12
+ date: 2013-04-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -58,7 +58,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
58
58
  version: '0'
59
59
  segments:
60
60
  - 0
61
- hash: 460637235756246510
61
+ hash: -596763061643403807
62
62
  required_rubygems_version: !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  version: '0'
68
68
  segments:
69
69
  - 0
70
- hash: 460637235756246510
70
+ hash: -596763061643403807
71
71
  requirements: []
72
72
  rubyforge_project:
73
73
  rubygems_version: 1.8.23