presto-metrics 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67e17b9feb19f715c198b3aa1dfb024acecdf4f3
4
- data.tar.gz: e8cb9299fd641dfa73a2e2e7fe9a30d4df5e5759
3
+ metadata.gz: a43804112e1f231ae1f0385b6d4c23909d4b0c37
4
+ data.tar.gz: ee961aa3796169912449f4db7c4fac1870dd8362
5
5
  SHA512:
6
- metadata.gz: 66c4ab07df7446d229dcd61c99aba4c5c964afad16dd810901eff29004c228535fd545468700a6eba913e182c4d3a9be1eccde0f3d96012b1479c8b940fa00ca
7
- data.tar.gz: 2fbc03bc8ab865032b384ce3ed6c40628faa82efd91b2fa7b6e4b92e403dec135414d8e73a1f9ed8f291a49d57c6ffc0d0720bb9499b2b7ab431363e9381d107
6
+ metadata.gz: ac35fadd641b03a7609d3067bef8b0fbca98e8869c9130f0a6ac19aba5c1c3e0675da3788572ff3cf2eb5b223822f4c895955d5dd2c5b44e053189923281ccd0
7
+ data.tar.gz: c6856141ac447e3b2eed0b07025ad5856e5f64ba6e75e1806598ea3a0730387c4d5069010210d9f706cc19e8ab95355b1437e37cc934865a2e0c07b348edde81
data/README.md CHANGED
@@ -29,7 +29,8 @@ require 'presto/metrics'
29
29
  client = Presto::Metrics::Client.new # Access to http://localhost:8080 in default
30
30
 
31
31
  # Alternatively, you can specify the host name and port number to use
32
- client = Presto::Metrics::Client.new(:host => "localhost", :port=>8081)
32
+ client = Presto::Metrics::Client.new(:host => "localhost", :port=>8080)
33
+
33
34
 
34
35
 
35
36
  client.os_metrics
@@ -38,12 +39,23 @@ client.os_metrics
38
39
  # This is equivalent to write as follows
39
40
  client.get_metrics("java.lang:type=OperatingSystem")
40
41
 
41
- # Retrieve a set of parameters
42
+ # Retrieve a specific set of parameters
42
43
  client.query_manager_metrics(["executor.active_count", "executor.completed_task_count"])
43
44
  # => {:"executor.active_count"=>0, :"executor.completed_task_count"=>0}
45
+
44
46
  client.os_metrics([:system_load_average, :free_physical_memory_size])
45
47
  #=> {:free_physical_memory_size=>3690512384, :system_load_average=>2.33056640625}
46
48
 
49
+
50
+ # Path queries
51
+ client.path("os:physical_memory_size")
52
+ # => {"os.free_physical_memory_size"=>55034294272}
53
+
54
+ # You can use comma-separated list of path queries
55
+ client.path("memory:heap_memory_usage.used,non_heap_memory_usage.used")
56
+ # => {"heap_memory_usage.used"=>926714864, "non_heap_memory_usage.used"=>108948488}
57
+
58
+
47
59
  # Retrieve standard metrics
48
60
  client.memory_usage_metrics # java.lang:Type=Memory
49
61
  client.os_metrics # java.lang:type=OperatingSystm
@@ -58,11 +70,32 @@ client.task_manager_metrics # com.facebook.presto.execution:name=TaskManage
58
70
  # Retrieve the JSON representation of JMX properties
59
71
  client.get_json("java.lang:Type=Memory")
60
72
 
73
+ # Pretty print
74
+ require 'pp'
75
+ pp c.memory_usage_metrics
76
+ #{
77
+ # "verbose": false,
78
+ # "object_pending_finalization_count": 0,
79
+ # "heap_memory_usage": {
80
+ # "committed": 259522560,
81
+ # "init": 268435456,
82
+ # "max": 14962655232,
83
+ # "used": 84478072
84
+ # },
85
+ # "non_heap_memory_usage": {
86
+ # "committed": 163250176,
87
+ # "init": 159842304,
88
+ # "max": 471859200,
89
+ # "used": 53369528
90
+ 3 },
91
+ # "object_name": "java.lang:type=Memory"
92
+ #}
93
+
61
94
  ```
62
95
 
63
96
  ## Contributing
64
97
 
65
- 1. Fork it ( https://github.com/[my-github-username]/presto-metrics/fork )
98
+ 1. Fork it ( https://github.com/xerial/presto-metrics/fork )
66
99
  2. Create your feature branch (`git checkout -b my-new-feature`)
67
100
  3. Commit your changes (`git commit -am 'Add some feature'`)
68
101
  4. Push to the branch (`git push origin my-new-feature`)
@@ -1,30 +1,97 @@
1
1
  require "presto/metrics/version"
2
2
  require 'httparty'
3
3
  require 'json'
4
+ require 'jsonpath'
4
5
 
5
6
  module Presto
6
7
  module Metrics
7
8
 
9
+ class Query
10
+ def initialize(client)
11
+ @client = client
12
+ end
13
+
14
+ def list
15
+ query_list().each {|q|
16
+ s = q['session'] || {}
17
+ query = q['query'].gsub(/[\r\n]/, " ")[0..50]
18
+ c = [q['queryId'], s['user'], s['catalog'], s['schema'], s['source'], query]
19
+ puts c.join("\t")
20
+ }
21
+ 0
22
+ end
23
+
24
+ def find(id)
25
+ @client.get_query_json(id)
26
+ end
27
+
28
+ def query_list(path="")
29
+ JSON.parse(@client.get_query_json(path))
30
+ end
31
+
32
+ end
33
+
8
34
  class Client
9
35
  def initialize(opts={})
10
36
  @host = opts[:host] || "localhost"
11
37
  @port = opts[:port] || "8080"
12
38
  @endpoint = opts[:endpoint] || "http://#{@host}:#{@port}"
13
- @mbean_path = opts[:mbean_path] || "/v1/jmx/mbean/"
39
+ @mbean_path = opts[:mbean_path] || "/v1/jmx/mbean"
40
+ @query_path = opts[:query_path] || "/v1/query"
14
41
  @caml_case = opts[:caml_case] || false
15
42
  end
16
43
 
17
- def get(mbean)
18
- JSON.parse(get_json(mbean))
44
+ @@MBEAN_ALIAS = {
45
+ "memory" => "java.lang:type=Memory",
46
+ "gc_cms" => "java.lang:type=GarbageCollector,name=ConcurrentMarkSweep",
47
+ "gc_parnew" => "java.lang:type=GarbageCollector,name=ParNew",
48
+ "os" => "java.lang:type=OperatingSystem",
49
+ "query_manager" => "com.facebook.presto.execution:name=QueryManager",
50
+ "query_execution" => "com.facebook.presto.execution:name=QueryExecution",
51
+ "node_scheduler" => "com.facebook.presto.execution:name=NodeScheduler",
52
+ "task_executor" => "com.facebook.presto.execution:name=TaskExecutor",
53
+ "task_manager" => "com.facebook.presto.execution:name=TaskManager"
54
+ }
55
+
56
+
57
+ def path(path)
58
+ c = path.split(/:/)
59
+ target = c[0]
60
+ mbean = @@MBEAN_ALIAS[target] || target
61
+ json = get_metrics(mbean)
62
+ return json if c.size <= 1
63
+ query_list = (c[1] || "").split(/,/)
64
+ result = {}
65
+ query_list.each{|q|
66
+ json_path = JsonPath.new(q)
67
+ result[q] = json_path.first(json)
68
+ }
69
+ result
70
+ end
71
+
72
+ def query
73
+ Query.new(self)
74
+ end
75
+
76
+ def get_mbean(mbean)
77
+ JSON.parse(get_mbean_json(mbean))
78
+ end
79
+
80
+ def get(path)
81
+ resp = HTTParty.get("#{@endpoint}#{path}")
82
+ resp.body
19
83
  end
20
84
 
21
- def get_json(mbean)
22
- resp = HTTParty.get("#{@endpoint}#{@mbean_path}#{mbean}")
23
- resp.body
85
+ def get_mbean_json(mbean)
86
+ get("#{@mbean_path}/#{mbean}")
24
87
  end
25
88
 
89
+ def get_query_json(path="")
90
+ get("#{@query_path}/#{path}")
91
+ end
92
+
26
93
  def get_attributes(mbean)
27
- json = get(mbean)
94
+ json = get_mbean(mbean)
28
95
  json['attributes'] || []
29
96
  end
30
97
 
@@ -57,13 +124,14 @@ module Presto
57
124
  .each {|attr|
58
125
  c_name = to_canonical_name(attr['name'])
59
126
  if c_target_attr.empty? || c_target_attr.include?(c_name)
60
- key = @caml_case ? attr['name'] : underscore(attr['name']).to_sym
127
+ key = @caml_case ? attr['name'] : underscore(attr['name'])
61
128
  kv[key] = attr['value']
62
129
  end
63
130
  }
64
131
  kv
65
132
  end
66
133
 
134
+
67
135
  def memory_usage_metrics(target_attr=[])
68
136
  get_metrics("java.lang:type=Memory", target_attr)
69
137
  end
@@ -1,5 +1,5 @@
1
1
  module Presto
2
2
  module Metrics
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Taro L. Saito"]
10
10
  spec.email = ["leo@xerial.org"]
11
11
  spec.summary = "A library for collecting metrics of Presto, a distributed SQL engine"
12
- spec.description = "Monitoring the states of Presto coordinator and worker processes through JMX REST API (/v1/jmx/mbean)"
12
+ spec.description = "Monitoring Presto coordinator and worker processes through JMX REST API (/v1/jmx/mbean)"
13
13
  spec.homepage = "https://github.com/xerial/presto-metrics"
14
14
  spec.license = "MIT"
15
15
 
@@ -23,4 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "rspec"
24
24
 
25
25
  spec.add_runtime_dependency "httparty"
26
+ spec.add_runtime_dependency "jsonpath"
27
+
26
28
  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.1.0
4
+ version: 0.1.1
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: 2014-08-26 00:00:00.000000000 Z
11
+ date: 2014-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,8 +66,22 @@ dependencies:
66
66
  - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description: Monitoring the states of Presto coordinator and worker processes through
70
- JMX REST API (/v1/jmx/mbean)
69
+ - !ruby/object:Gem::Dependency
70
+ name: jsonpath
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Monitoring Presto coordinator and worker processes through JMX REST API
84
+ (/v1/jmx/mbean)
71
85
  email:
72
86
  - leo@xerial.org
73
87
  executables: []
@@ -113,3 +127,4 @@ summary: A library for collecting metrics of Presto, a distributed SQL engine
113
127
  test_files:
114
128
  - spec/presto/metrics_spec.rb
115
129
  - spec/spec_helper.rb
130
+ has_rdoc: