presto-metrics 0.1.1 → 0.2.0

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: a43804112e1f231ae1f0385b6d4c23909d4b0c37
4
- data.tar.gz: ee961aa3796169912449f4db7c4fac1870dd8362
3
+ metadata.gz: 0a2bf2d4c30bd55568e9b94d7f9fd1597303a8d3
4
+ data.tar.gz: 0f7c7864bacaa407c2c526d6f1d3ac3eb6e36c1d
5
5
  SHA512:
6
- metadata.gz: ac35fadd641b03a7609d3067bef8b0fbca98e8869c9130f0a6ac19aba5c1c3e0675da3788572ff3cf2eb5b223822f4c895955d5dd2c5b44e053189923281ccd0
7
- data.tar.gz: c6856141ac447e3b2eed0b07025ad5856e5f64ba6e75e1806598ea3a0730387c4d5069010210d9f706cc19e8ab95355b1437e37cc934865a2e0c07b348edde81
6
+ metadata.gz: e944e66ed17d4a470e407d4c7078908f9d4f248ab739b138397a6eda7c4acb7788fb9b5cbf9f2d1327a26fd9cea5293dab6631b23af2000691aa361270752d46
7
+ data.tar.gz: e4558c716d9f80925f7892a8c2a19062f119575c8353e279653097fc542633d536240824d1e7332929eeccfd3f483c4acec40693988a1c2cdf10c09448d2a5a2
data/README.md CHANGED
@@ -49,11 +49,11 @@ client.os_metrics([:system_load_average, :free_physical_memory_size])
49
49
 
50
50
  # Path queries
51
51
  client.path("os:physical_memory_size")
52
- # => {"os.free_physical_memory_size"=>55034294272}
52
+ # => {"free_physical_memory_size"=>55034294272}
53
53
 
54
54
  # You can use comma-separated list of path queries
55
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}
56
+ # => {"heap_memory_usage/used"=>926714864, "non_heap_memory_usage/used"=>108948488}
57
57
 
58
58
 
59
59
  # Retrieve standard metrics
@@ -1,7 +1,6 @@
1
1
  require "presto/metrics/version"
2
2
  require 'httparty'
3
3
  require 'json'
4
- require 'jsonpath'
5
4
 
6
5
  module Presto
7
6
  module Metrics
@@ -58,17 +57,36 @@ module Presto
58
57
  c = path.split(/:/)
59
58
  target = c[0]
60
59
  mbean = @@MBEAN_ALIAS[target] || target
61
- json = get_metrics(mbean)
62
- return json if c.size <= 1
60
+ json_obj = get_metrics(mbean)
61
+ return json_obj if c.size <= 1
63
62
  query_list = (c[1] || "").split(/,/)
64
63
  result = {}
65
64
  query_list.each{|q|
66
- json_path = JsonPath.new(q)
67
- result[q] = json_path.first(json)
65
+ path_elems = q.split("/")
66
+ target_elem = extract_path(json_obj, path_elems, 0)
67
+ result[q] = target_elem unless target_elem.nil?
68
68
  }
69
69
  result
70
70
  end
71
71
 
72
+
73
+ def extract_path(json_obj, path, depth)
74
+ return nil if json_obj.nil?
75
+ if depth >= path.length
76
+ json_obj
77
+ else
78
+ if json_obj.kind_of?(Array)
79
+ # Handle key, value pairs of GC information
80
+ value = json_obj.find{|e|
81
+ e.is_a?(Hash) && e['key'] == path[depth]
82
+ }
83
+ extract_path(value['value'], path, depth+1)
84
+ else
85
+ extract_path(json_obj[path[depth]], path, depth+1)
86
+ end
87
+ end
88
+ end
89
+
72
90
  def query
73
91
  Query.new(self)
74
92
  end
@@ -79,7 +97,11 @@ module Presto
79
97
 
80
98
  def get(path)
81
99
  resp = HTTParty.get("#{@endpoint}#{path}")
82
- resp.body
100
+ if resp.code == 200
101
+ resp.body
102
+ else
103
+ "{}"
104
+ end
83
105
  end
84
106
 
85
107
  def get_mbean_json(mbean)
@@ -1,5 +1,5 @@
1
1
  module Presto
2
2
  module Metrics
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -23,6 +23,5 @@ 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
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: presto-metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taro L. Saito
@@ -66,20 +66,6 @@ dependencies:
66
66
  - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
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
69
  description: Monitoring Presto coordinator and worker processes through JMX REST API
84
70
  (/v1/jmx/mbean)
85
71
  email: