presto-metrics 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 20f88464eb58713f773bc24d7f516f3f4a31f819
4
+ data.tar.gz: 8d1598547abeaf89260ef9d20b87824bb379bd25
5
+ SHA512:
6
+ metadata.gz: b22ce44ca5bca80e2b23054afa1eb7d95a04e60f8badad6140bd657d5df0a0f8c17bf48e04fe5bc28afebf62d40478cabc77c508c7e0c973c8483aaba2239b14
7
+ data.tar.gz: af635b4094ab5fe5f7c1d026ffc295ad35594f11e0b70620decac778420779956ac9118a16ac1bda5152a71a4a826ae1106f7859c4e64ab01695aafbcb4921c5
data/README.md CHANGED
@@ -67,6 +67,30 @@ client.node_scheduler_metrics # com.facebook.presto.execution:name=NodeSchedu
67
67
  client.task_executor_metrics # com.facebook.presto.execution:name=TaskExecutor
68
68
  client.task_manager_metrics # com.facebook.presto.execution:name=TaskManager
69
69
 
70
+ # Retrieve presto worker metrics
71
+ pp client.node_metrics
72
+ [{"host"=>"xxx.xxx.xxx.xxx",
73
+ "uri"=>"http://xxx.xxx.xxx.xxx:8080",
74
+ "recent_requests"=>120.00277776491774,
75
+ "recent_failures"=>0.0,
76
+ "recent_successes"=>120.0027781973587,
77
+ "last_request_time"=>"2015-03-19T03:27:23.242Z",
78
+ "last_response_time"=>"2015-03-19T03:27:23.243Z",
79
+ "recent_failure_ratio"=>0.0,
80
+ "age"=>"38.56m",
81
+ "recent_failures_by_type"=>{}},
82
+ {"host"=>"yyy.yyy.yyy.yyy",
83
+ "uri"=>"http://yyy.yyy.yyy.yyy:8080",
84
+ "recent_requests"=>120.00277776491774,
85
+ "recent_failures"=>0.0,
86
+ "recent_successes"=>120.0027777649236,
87
+ "last_request_time"=>"2015-03-19T03:27:23.242Z",
88
+ "last_response_time"=>"2015-03-19T03:27:23.243Z",
89
+ "recent_failure_ratio"=>0.0,
90
+ "age"=>"38.56m",
91
+ "recent_failures_by_type"=>{}}]
92
+
93
+
70
94
  # Retrieve the JSON representation of JMX properties
71
95
  client.get_json("java.lang:Type=Memory")
72
96
 
@@ -1,174 +1,190 @@
1
-
2
1
  module Presto
3
2
  module Metrics
4
3
 
5
- class Client
6
- def initialize(opts={})
7
- require 'httparty'
8
- require 'json'
9
- require 'set'
10
- require 'time'
11
-
12
- @host = opts[:host] || 'localhost'
13
- @port = opts[:port] || '8080'
14
- @endpoint = opts[:endpoint] || "http://#{@host}:#{@port}"
15
- @mbean_path = opts[:mbean_path] || '/v1/jmx/mbean'
16
- @query_path = opts[:query_path] || '/v1/query'
17
- @caml_case = opts[:caml_case] || false
18
- end
19
-
20
- @@MBEAN_ALIAS = {
21
- 'memory' => 'java.lang:type=Memory',
22
- 'gc_cms' => 'java.lang:type=GarbageCollector,name=ConcurrentMarkSweep',
23
- 'gc_parnew' => 'java.lang:type=GarbageCollector,name=ParNew',
24
- 'os' => 'java.lang:type=OperatingSystem',
25
- 'query_manager' => 'com.facebook.presto.execution:name=QueryManager',
26
- 'query_execution' => 'com.facebook.presto.execution:name=QueryExecution',
27
- 'node_scheduler' => 'com.facebook.presto.execution:name=NodeScheduler',
28
- 'task_executor' => 'com.facebook.presto.execution:name=TaskExecutor',
29
- 'task_manager' => 'com.facebook.presto.execution:name=TaskManager'
30
- }
31
-
32
-
33
- def path(path)
34
- c = path.split(/:/)
35
- target = c[0]
36
- mbean = @@MBEAN_ALIAS[target] || target
37
- json_obj = get_metrics(mbean)
38
- return json_obj if c.size <= 1
39
- query_list = (c[1] || '').split(/,/)
40
- result = {}
41
- query_list.each{|q|
42
- path_elems = q.split('/')
43
- target_elem = extract_path(json_obj, path_elems, 0)
44
- result[q] = target_elem unless target_elem.nil?
45
- }
46
- result
47
- end
48
-
49
-
50
- def extract_path(json_obj, path, depth)
51
- return nil if json_obj.nil?
52
- if depth >= path.length
53
- json_obj
54
- else
55
- if json_obj.kind_of?(Array)
56
- # Handle key, value pairs of GC information
57
- value = json_obj.find{|e|
58
- e.is_a?(Hash) && e['key'] == path[depth]
59
- }
60
- extract_path(value['value'], path, depth+1)
61
- else
62
- extract_path(json_obj[path[depth]], path, depth+1)
63
- end
64
- end
65
- end
66
-
67
- def query
68
- Query.new(self)
69
- end
70
-
71
- def get_mbean(mbean)
72
- JSON.parse(get_mbean_json(mbean))
73
- end
74
-
75
- def get(path, default='{}')
76
- resp = HTTParty.get("#{@endpoint}#{path}")
77
- if resp.code == 200
78
- resp.body
79
- else
80
- default
81
- end
82
- end
83
-
84
- def get_mbean_json(mbean)
85
- get("#{@mbean_path}/#{mbean}")
86
- end
87
-
88
- def get_query_json(path='', default='[]')
89
- get("#{@query_path}/#{path}",default)
90
- end
91
-
92
- def get_attributes(mbean)
93
- json = get_mbean(mbean)
94
- json['attributes'] || []
95
- end
96
-
97
- def get_attribute(mbean, attr_name)
98
- get_attributes(mbean).find {|obj| obj['name'] == attr_name } || {}
99
- end
100
-
101
- def map_to_canonical_name(name_arr)
102
- name_arr.map{|name| to_canonical_name(name) }
103
- end
104
-
105
- def to_canonical_name(name)
106
- name.to_s.downcase.gsub(/_/, '')
107
- end
108
-
109
- def underscore(str)
110
- str.gsub(/::/, '/').
111
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
112
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
113
- tr('-', '_').
114
- downcase
115
- end
116
-
117
- def get_metrics(mbean, target_attr=[])
118
- kv = Hash.new
119
- arr = target_attr.kind_of?(Array) ? target_attr : [target_attr]
120
- c_target_attr = map_to_canonical_name(arr).to_set
121
- get_attributes(mbean)
122
- .reject {|attr| attr['name'].nil? || attr['value'].nil? }
123
- .each {|attr|
124
- c_name = to_canonical_name(attr['name'])
125
- if c_target_attr.empty? || c_target_attr.include?(c_name)
126
- key = @caml_case ? attr['name'] : underscore(attr['name'])
127
- kv[key] = attr['value']
128
- end
129
- }
130
- kv
131
- end
132
-
133
-
134
- def memory_usage_metrics(target_attr=[])
135
- get_metrics('java.lang:type=Memory', target_attr)
136
- end
137
-
138
- def gc_cms_metrics(target_attr=[])
139
- get_metrics('java.lang:type=GarbageCollector,name=ConcurrentMarkSweep', target_attr)
140
- end
141
-
142
- def gc_parnew_metrics(target_attr=[])
143
- get_metrics('java.lang:type=GarbageCollector,name=ParNew', target_attr)
144
- end
145
-
146
- def os_metrics(target_attr=[])
147
- get_metrics('java.lang:type=OperatingSystem', target_attr)
148
- end
149
-
150
- def query_manager_metrics(target_attr=[])
151
- get_metrics('com.facebook.presto.execution:name=QueryManager', target_attr)
152
- end
153
-
154
- def query_execution_metrics(target_attr=[])
155
- get_metrics('com.facebook.presto.execution:name=QueryExecution', target_attr)
156
- end
157
-
158
- def node_scheduler_metrics(target_attr=[])
159
- get_metrics('com.facebook.presto.execution:name=NodeScheduler', target_attr)
160
- end
161
-
162
- def task_executor_metrics(target_attr=[])
163
- get_metrics('com.facebook.presto.execution:name=TaskExecutor', target_attr)
164
- end
165
-
166
- def task_manager_metrics(target_attr=[])
167
- get_metrics('com.facebook.presto.execution:name=TaskManager', target_attr)
168
- end
169
-
170
- private :map_to_canonical_name, :to_canonical_name, :underscore
171
- end
4
+ class Client
5
+ def initialize(opts={})
6
+ require 'httparty'
7
+ require 'json'
8
+ require 'set'
9
+ require 'time'
10
+
11
+ @host = opts[:host] || 'localhost'
12
+ @port = opts[:port] || '8080'
13
+ @endpoint = opts[:endpoint] || "http://#{@host}:#{@port}"
14
+ @mbean_path = opts[:mbean_path] || '/v1/jmx/mbean'
15
+ @query_path = opts[:query_path] || '/v1/query'
16
+ @node_path = opts[:node_path] || '/v1/node'
17
+ @caml_case = opts[:caml_case] || false
18
+ end
19
+
20
+ @@MBEAN_ALIAS = {
21
+ 'memory' => 'java.lang:type=Memory',
22
+ 'gc_cms' => 'java.lang:type=GarbageCollector,name=ConcurrentMarkSweep',
23
+ 'gc_parnew' => 'java.lang:type=GarbageCollector,name=ParNew',
24
+ 'os' => 'java.lang:type=OperatingSystem',
25
+ 'query_manager' => 'com.facebook.presto.execution:name=QueryManager',
26
+ 'query_execution' => 'com.facebook.presto.execution:name=QueryExecution',
27
+ 'node_scheduler' => 'com.facebook.presto.execution:name=NodeScheduler',
28
+ 'task_executor' => 'com.facebook.presto.execution:name=TaskExecutor',
29
+ 'task_manager' => 'com.facebook.presto.execution:name=TaskManager'
30
+ }
31
+
32
+ def path(path)
33
+ c = path.split(/:/)
34
+ target = c[0]
35
+ mbean = @@MBEAN_ALIAS[target] || target
36
+ json_obj = get_metrics(mbean)
37
+ return json_obj if c.size <= 1
38
+ query_list = (c[1] || '').split(/,/)
39
+ result = {}
40
+ query_list.each { |q|
41
+ path_elems = q.split('/')
42
+ target_elem = extract_path(json_obj, path_elems, 0)
43
+ result[q] = target_elem unless target_elem.nil?
44
+ }
45
+ result
46
+ end
47
+
48
+ def extract_path(json_obj, path, depth)
49
+ return nil if json_obj.nil?
50
+ if depth >= path.length
51
+ json_obj
52
+ else
53
+ if json_obj.kind_of?(Array)
54
+ # Handle key, value pairs of GC information
55
+ value = json_obj.find { |e|
56
+ e.is_a?(Hash) && e['key'] == path[depth]
57
+ }
58
+ extract_path(value['value'], path, depth+1)
59
+ else
60
+ extract_path(json_obj[path[depth]], path, depth+1)
61
+ end
62
+ end
63
+ end
64
+
65
+ def query
66
+ Query.new(self)
67
+ end
68
+
69
+ def get_mbean(mbean)
70
+ JSON.parse(get_mbean_json(mbean))
71
+ end
72
+
73
+ def get(path, default='{}')
74
+ resp = HTTParty.get("#{@endpoint}#{path}")
75
+ if resp.code == 200
76
+ resp.body
77
+ else
78
+ default
79
+ end
80
+ end
81
+
82
+ def get_mbean_json(mbean)
83
+ get("#{@mbean_path}/#{mbean}")
84
+ end
85
+
86
+ def get_query_json(path='', default='[]')
87
+ get("#{@query_path}/#{path}", default)
88
+ end
89
+
90
+ def get_node_json
91
+ get(@node_path)
92
+ end
93
+
94
+ def get_attributes(mbean)
95
+ json = get_mbean(mbean)
96
+ json['attributes'] || []
97
+ end
98
+
99
+ def get_attribute(mbean, attr_name)
100
+ get_attributes(mbean).find { |obj| obj['name'] == attr_name } || {}
101
+ end
102
+
103
+ def map_to_canonical_name(name_arr)
104
+ name_arr.map { |name| to_canonical_name(name) }
105
+ end
106
+
107
+ def to_canonical_name(name)
108
+ name.to_s.downcase.gsub(/_/, '')
109
+ end
110
+
111
+ def underscore(str)
112
+ str.gsub(/::/, '/').
113
+ gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
114
+ gsub(/([a-z\d])([A-Z])/, '\1_\2').
115
+ tr('-', '_').
116
+ downcase
117
+ end
118
+
119
+ def get_metrics(mbean, target_attr=[])
120
+ kv = Hash.new
121
+ arr = target_attr.kind_of?(Array) ? target_attr : [target_attr]
122
+ c_target_attr = map_to_canonical_name(arr).to_set
123
+ get_attributes(mbean)
124
+ .reject { |attr| attr['name'].nil? || attr['value'].nil? }
125
+ .each { |attr|
126
+ c_name = to_canonical_name(attr['name'])
127
+ if c_target_attr.empty? || c_target_attr.include?(c_name)
128
+ key = @caml_case ? attr['name'] : underscore(attr['name'])
129
+ kv[key] = attr['value']
130
+ end
131
+ }
132
+ kv
133
+ end
134
+
135
+ def memory_usage_metrics(target_attr=[])
136
+ get_metrics('java.lang:type=Memory', target_attr)
137
+ end
138
+
139
+ def gc_cms_metrics(target_attr=[])
140
+ get_metrics('java.lang:type=GarbageCollector,name=ConcurrentMarkSweep', target_attr)
141
+ end
142
+
143
+ def gc_parnew_metrics(target_attr=[])
144
+ get_metrics('java.lang:type=GarbageCollector,name=ParNew', target_attr)
145
+ end
146
+
147
+ def os_metrics(target_attr=[])
148
+ get_metrics('java.lang:type=OperatingSystem', target_attr)
149
+ end
150
+
151
+ def query_manager_metrics(target_attr=[])
152
+ get_metrics('com.facebook.presto.execution:name=QueryManager', target_attr)
153
+ end
154
+
155
+ def query_execution_metrics(target_attr=[])
156
+ get_metrics('com.facebook.presto.execution:name=QueryExecution', target_attr)
157
+ end
158
+
159
+ def node_scheduler_metrics(target_attr=[])
160
+ get_metrics('com.facebook.presto.execution:name=NodeScheduler', target_attr)
161
+ end
162
+
163
+ def task_executor_metrics(target_attr=[])
164
+ get_metrics('com.facebook.presto.execution:name=TaskExecutor', target_attr)
165
+ end
166
+
167
+ def task_manager_metrics(target_attr=[])
168
+ get_metrics('com.facebook.presto.execution:name=TaskManager', target_attr)
169
+ end
170
+
171
+ def node_metrics(target_attr=[])
172
+ p = URI::Parser.new
173
+ node_state = JSON.parse(get_node_json)
174
+ node_state.map{|n|
175
+ uri = n['uri'] || ''
176
+ m = {}
177
+ m['host'] = p.parse(uri).host
178
+ n.each{|k, v|
179
+ key = @caml_case ? k : underscore(k)
180
+ m[key] = v
181
+ }
182
+ m
183
+ }
184
+ end
185
+
186
+ private :map_to_canonical_name, :to_canonical_name, :underscore
187
+ end
172
188
  end
173
189
  end
174
190
 
@@ -1,5 +1,5 @@
1
1
  module Presto
2
2
  module Metrics
3
- VERSION = '0.3.6'
3
+ VERSION = '0.3.7'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,110 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: presto-metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
5
- prerelease:
4
+ version: 0.3.7
6
5
  platform: ruby
7
6
  authors:
8
7
  - Taro L. Saito
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2015-01-14 00:00:00.000000000 Z
11
+ date: 2015-03-19 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '1.7'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '1.7'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
33
  version: '10.0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
40
  version: '10.0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: presto-client
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ~>
59
+ - - "~>"
68
60
  - !ruby/object:Gem::Version
69
61
  version: 0.4.4
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ~>
66
+ - - "~>"
76
67
  - !ruby/object:Gem::Version
77
68
  version: 0.4.4
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: httpclient
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - ">="
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - ">="
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: httparty
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - ">="
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :runtime
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - ">="
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  description: Monitoring Presto coordinator and worker processes through JMX REST API
@@ -115,9 +102,9 @@ executables: []
115
102
  extensions: []
116
103
  extra_rdoc_files: []
117
104
  files:
118
- - .gitignore
119
- - .rspec
120
- - .travis.yml
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
121
108
  - Gemfile
122
109
  - LICENSE.txt
123
110
  - README.md
@@ -132,27 +119,26 @@ files:
132
119
  homepage: https://github.com/xerial/presto-metrics
133
120
  licenses:
134
121
  - MIT
122
+ metadata: {}
135
123
  post_install_message:
136
124
  rdoc_options: []
137
125
  require_paths:
138
126
  - lib
139
127
  required_ruby_version: !ruby/object:Gem::Requirement
140
- none: false
141
128
  requirements:
142
- - - ! '>='
129
+ - - ">="
143
130
  - !ruby/object:Gem::Version
144
131
  version: '0'
145
132
  required_rubygems_version: !ruby/object:Gem::Requirement
146
- none: false
147
133
  requirements:
148
- - - ! '>='
134
+ - - ">="
149
135
  - !ruby/object:Gem::Version
150
136
  version: '0'
151
137
  requirements: []
152
138
  rubyforge_project:
153
- rubygems_version: 1.8.23
139
+ rubygems_version: 2.4.5
154
140
  signing_key:
155
- specification_version: 3
141
+ specification_version: 4
156
142
  summary: A library for collecting metrics of Presto, a distributed SQL engine
157
143
  test_files:
158
144
  - spec/presto/metrics_spec.rb