presto-metrics 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dbbf348083479afcf19bae2f803048d9670ce93e
4
- data.tar.gz: 394b1e332c7d5c951194dfa042ca1d48ac5d6f4d
3
+ metadata.gz: a3c3d3f74169faa3e4cae0abe8eeb502faea7585
4
+ data.tar.gz: f2284da30958c56c7c23924379b159660a4c9e23
5
5
  SHA512:
6
- metadata.gz: 5fb347c82a24cdd4ba8852784903ab788ea353475e5e1ae808f673895bcd09e6b5f92c2e6e1fc0d52270d1918e7fc671b8e61b85c63d08ad698549ccbff4edb1
7
- data.tar.gz: 53bcaf2db51f5076a071b8eca41685158af78a8d4a215de271c867241466f53eb612b5370d0d12b65fc2e9491c84db8e4b49ebf2c6e8da1c1814a71f34c4cabb
6
+ metadata.gz: 8fafeb893d3f45120d0ad23a27359be2df3ebdc74d1dbe982c2f5a97c04c0ac43868032ee499e0ac29e4ba66f0b819d8e140544c4e1348ea4c66f889d7871643
7
+ data.tar.gz: eba6f37b29ccc3f3e2eca0967c28ec70d4b25a3c2cf3aab8f78dbc5d9eb89fc2e76934ca5c5dcdec0bf444dd6091f84e9f4dc4a3ad6e62dc0f529f8edc903284
data/README.md CHANGED
@@ -32,7 +32,6 @@ client = Presto::Metrics::Client.new # Access to http://localhost:8080 in defau
32
32
  client = Presto::Metrics::Client.new(:host => "localhost", :port=>8080)
33
33
 
34
34
 
35
-
36
35
  client.os_metrics
37
36
  # => {:open_file_descriptor_count=>360, :max_file_descriptor_count=>10240, :committed_virtual_memory_size=>18683629568, :total_swap_space_size=>2147483648, :free_swap_space_size=>1132986368, :process_cpu_time=>240244441000, :free_physical_memory_size=>2088931328, :total_physical_memory_size=>17179869184, :system_cpu_load=>0.044989775051124746, :process_cpu_load=>0.002293214043176635, :name=>"Mac OS X", :version=>"10.9.4", :available_processors=>8, :arch=>"x86_64", :system_load_average=>2.0537109375, :object_name=>"java.lang:type=OperatingSystem"}
38
37
 
@@ -61,13 +60,25 @@ client.memory_usage_metrics # java.lang:Type=Memory
61
60
  client.os_metrics # java.lang:type=OperatingSystm
62
61
  client.gc_cms_metrics # java.lang:type=GarbageCollector,name=ConcurrentMarkSweep
63
62
  client.gc_parnew_metrics # java.lang:type=GarbageCollector,name=ParNew
64
- client.gc_g1_metrics # java.lang:type=GarbageCollector,name=G1
63
+ client.gc_g1_metrics # java.lang:type=GarbageCollector,name=G1 Young Generation and G1 Old Genration
65
64
  client.query_manager_metrics # com.facebook.presto.execution:name=QueryManager
66
65
  client.query_execution_metrics # com.facebook.presto.execution:name=QueryExecution
67
66
  client.node_scheduler_metrics # com.facebook.presto.execution:name=NodeScheduler
68
67
  client.task_executor_metrics # com.facebook.presto.execution:name=TaskExecutor
69
68
  client.task_manager_metrics # com.facebook.presto.execution:name=TaskManager
70
69
 
70
+
71
+ # Memory resource manager metrics (since Presto 0.103)
72
+ ```ruby
73
+ client.memory_pool_metrics
74
+ => {"general"=>{"free_bytes"=>59700045415, "max_bytes"=>59700045415}, "reserved"=>{"free_bytes"=>2147483648, "max_bytes"=>2147483648}}
75
+
76
+ client.cluster_memory_pool_metrics
77
+ => {"general"=>{"blocked_nodes"=>0, "free_distributed_bytes"=>116833832981, "nodes"=>4, "queries"=>8, "total_distributed_bytes"=>131855495989},
78
+ "reserved"=>{"blocked_nodes"=>0, "free_distributed_bytes"=>15032385536, "nodes"=>4, "queries"=>0, "total_distributed_bytes"=>15032385536}}
79
+ ```
80
+
81
+
71
82
  # Retrieve presto worker metrics
72
83
  pp client.node_metrics
73
84
  [{"host"=>"xxx.xxx.xxx.xxx",
@@ -93,7 +104,7 @@ pp client.node_metrics
93
104
 
94
105
 
95
106
  # Retrieve the JSON representation of JMX properties
96
- client.get_json("java.lang:Type=Memory")
107
+ client.get_mbean_json("java.lang:Type=Memory")
97
108
 
98
109
  # Pretty print
99
110
  require 'pp'
@@ -125,3 +136,19 @@ pp c.memory_usage_metrics
125
136
  3. Commit your changes (`git commit -am 'Add some feature'`)
126
137
  4. Push to the branch (`git push origin my-new-feature`)
127
138
  5. Create a new Pull Request
139
+
140
+
141
+ ## For developers
142
+
143
+ To develop presto-metrics
144
+
145
+ ```
146
+ $ bundle exec irb -I lib -r presto/metrics.rb
147
+
148
+ irb> client = Presto::Metrics::Client.new(:host => "ec2-54-205-192-36.compute-1.amazonaws.com", :port=>8080)
149
+
150
+ # reload modified code
151
+ irb> load "presto/metrics/client.rb"
152
+
153
+ ```
154
+
@@ -7,6 +7,7 @@ module Presto
7
7
  require 'json'
8
8
  require 'set'
9
9
  require 'time'
10
+ require 'uri'
10
11
 
11
12
  @host = opts[:host] || 'localhost'
12
13
  @port = opts[:port] || '8080'
@@ -26,7 +27,12 @@ module Presto
26
27
  'query_execution' => 'com.facebook.presto.execution:name=QueryExecution',
27
28
  'node_scheduler' => 'com.facebook.presto.execution:name=NodeScheduler',
28
29
  'task_executor' => 'com.facebook.presto.execution:name=TaskExecutor',
29
- 'task_manager' => 'com.facebook.presto.execution:name=TaskManager'
30
+ 'task_manager' => 'com.facebook.presto.execution:name=TaskManager',
31
+ 'memory_pool_general' => 'com.facebook.presto.memory:type=MemoryPool,name=general',
32
+ 'memory_pool_reserved' => 'com.facebook.presto.memory:type=MemoryPool,name=reserved',
33
+ 'cluster_memory_manager' => 'com.facebook.presto.memory:name=ClusterMemoryManager',
34
+ 'cluster_memory_pool_general' => 'com.facebook.presto.memory:type=ClusterMemoryPool,name=general',
35
+ 'cluster_memory_pool_reserved' => 'com.facebook.presto.memory:type=ClusterMemoryPool,name=reserved',
30
36
  }
31
37
 
32
38
  def path(path)
@@ -71,7 +77,7 @@ module Presto
71
77
  end
72
78
 
73
79
  def get(path, default='{}')
74
- resp = HTTParty.get("#{@endpoint}#{path}")
80
+ resp = HTTParty.get(URI.encode("#{@endpoint}#{path}"))
75
81
  if resp.code == 200
76
82
  resp.body
77
83
  else
@@ -112,6 +118,7 @@ module Presto
112
118
  str.gsub(/::/, '/').
113
119
  gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
114
120
  gsub(/([a-z\d])([A-Z])/, '\1_\2').
121
+ gsub(/ +/,'_').
115
122
  tr('-', '_').
116
123
  downcase
117
124
  end
@@ -132,20 +139,55 @@ module Presto
132
139
  kv
133
140
  end
134
141
 
142
+ def sanitize_key(k)
143
+ @caml_case ? k : underscore(k)
144
+ end
145
+
146
+ def extract_value(v)
147
+ if v.is_a?(Hash)
148
+ if v.has_key?('key') && v.has_key?('value')
149
+ {sanitize_key(v['key']) => extract_value(v['value']) }
150
+ else
151
+ v.each_with_object({}) {|(k1, v1), h2|
152
+ h2[sanitize_key(k1)] = extract_value(v1)
153
+ }
154
+ end
155
+ elsif v.is_a?(Array) && v.all?{|e| e.is_a?(Hash) }
156
+ v.each_with_object({}){|e, h| h.merge!(extract_value(e)) }
157
+ else
158
+ v
159
+ end
160
+ end
161
+
162
+ def get_gc_metrics(mbean, target_attr=[])
163
+ h = {}
164
+ get_attributes(mbean)
165
+ .reject { |attr| attr['name'].nil? || attr['value'].nil? }
166
+ .each { |attr|
167
+ key = sanitize_key(attr['name'])
168
+ v = attr['value']
169
+ h[key] = extract_value(v)
170
+ }
171
+ h
172
+ end
173
+
174
+
135
175
  def memory_usage_metrics(target_attr=[])
136
176
  get_metrics('java.lang:type=Memory', target_attr)
137
177
  end
138
178
 
139
179
  def gc_cms_metrics(target_attr=[])
140
- get_metrics('java.lang:type=GarbageCollector,name=ConcurrentMarkSweep', target_attr)
180
+ get_gc_metrics('java.lang:type=GarbageCollector,name=ConcurrentMarkSweep', target_attr)
141
181
  end
142
182
 
143
183
  def gc_parnew_metrics(target_attr=[])
144
- get_metrics('java.lang:type=GarbageCollector,name=ParNew', target_attr)
184
+ get_gc_metrics('java.lang:type=GarbageCollector,name=ParNew', target_attr)
145
185
  end
146
186
 
147
187
  def gc_g1_metrics(target_attr=[])
148
- get_metrics('java.lang:type=GarbageCollector,name=G1', target_attr)
188
+ ['G1 Old Generation', 'G1 Young Generation'].each_with_object({}){|gen, h|
189
+ h[sanitize_key(gen)] = get_gc_metrics("java.lang:type=GarbageCollector,name=#{gen}", target_attr)
190
+ }
149
191
  end
150
192
 
151
193
  def os_metrics(target_attr=[])
@@ -172,6 +214,23 @@ module Presto
172
214
  get_metrics('com.facebook.presto.execution:name=TaskManager', target_attr)
173
215
  end
174
216
 
217
+ def memory_pool_metrics(target_attr=[])
218
+ ['general', 'reserved'].each_with_object({}) {|type, hash|
219
+ hash[type] = get_metrics("com.facebook.presto.memory:type=MemoryPool,name=#{type}", target_attr)
220
+ }
221
+ end
222
+
223
+ def cluster_memory_pool_metrics(target_attr=[])
224
+ ['general', 'reserved'].each_with_object({}) {|type, hash|
225
+ hash[type] = get_metrics("com.facebook.presto.memory:type=ClusterMemoryPool,name=#{type}", target_attr)
226
+ }
227
+ end
228
+
229
+ def cluster_memory_manager_metrics(target_attr=[])
230
+ get_metrics("com.facebook.presto.memory:name=ClusterMemoryManager", target_attr)
231
+ end
232
+
233
+
175
234
  def node_metrics(target_attr=[])
176
235
  p = URI::Parser.new
177
236
  node_state = JSON.parse(get_node_json)
@@ -59,11 +59,10 @@ module Presto
59
59
  [q['queryId'], q['elapsedTime'], q['state'], q['runningDrivers'], q['completedDrivers'], q['totalDrivers'], s['user'], s['catalog'], s['schema'], s['source'], query]
60
60
  }.sort_by{|row| row[0]}.reverse
61
61
 
62
- format_table(
63
- tbl,
64
- :label => %w|query time state r f t user catalog schema source sql|,
65
- :align => %w|r r r r r r l l r l l |,
66
- :sep => ' '
62
+ format_table(tbl,
63
+ %w|query time state r f t user catalog schema source sql|,
64
+ %w|r r r r r r l l r l l |,
65
+ ' '
67
66
  )
68
67
  end
69
68
 
@@ -73,9 +72,9 @@ module Presto
73
72
 
74
73
  def task_list(queryId)
75
74
  qj = find(queryId) || {}
76
- root_stage = qj['outputStage'] || []
75
+ root_stage = qj['outputStage'] || {}
77
76
  tasks = root_stage['tasks'] || []
78
- tasks << find_tasks(root_stage['subStages'])
77
+ tasks << find_tasks(root_stage['subStages'] || [])
79
78
  tasks.flatten
80
79
  end
81
80
 
@@ -87,9 +86,9 @@ module Presto
87
86
  [t['taskId'], host, t['state'], s['rawInputPositions'], s['rawInputDataSize'], s['queuedDrivers'], s['runningDrivers'], s['completedDrivers']]
88
87
  }
89
88
  format_table(stats,
90
- :label => %w|task_id host state processed_rows size|,
91
- :align => %w|l l l r r|,
92
- :sep => ' '
89
+ %w|task_id host state processed_rows size|,
90
+ %w|l l l r r|,
91
+ ' '
93
92
  )
94
93
  end
95
94
 
@@ -1,5 +1,5 @@
1
1
  module Presto
2
2
  module Metrics
3
- VERSION = '0.3.8'
3
+ VERSION = '0.3.9'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: presto-metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taro L. Saito
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-25 00:00:00.000000000 Z
11
+ date: 2015-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler