presto-metrics 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c54fe5aeea36ec72dc8d870d43343bb3f0077708
4
+ data.tar.gz: 069aa5598be94244fdafc04864a200d25417ef72
5
+ SHA512:
6
+ metadata.gz: 77230587d877b86283ba94b27d0348563def057f9882719555a7266375432797c487f97b0491024a551dce9d80815d63fc619d19b5ddb6ad5a9a625be496f48f
7
+ data.tar.gz: 19c7ce949770dc75e40b668c2e7f9753ddb06b726249001221aae24b0477c1d26107cb26688d9dfd425f68eb8d2a955dbc697eb4e02e57df52456db4bf871020
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in presto-metrics.gemspec
4
+ gemspec
5
+
6
+ gem "httparty", :require => true
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Taro L. Saito
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # Presto::Metrics
2
+
3
+ Presto is a distributed SQL engine, which launches coordinator and worker servers to process distributed queries in a cluster. We need to monitor the states of these coordinators/workers. Presto::Metrics is a library for accessing these states from Ruby.
4
+
5
+ Presto provides REST API for accessing JMX properties. Presto::Metrics accesses this REST API to extract JMX property values.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'presto-metrics'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install presto-metrics
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+
27
+ require 'presto/metrics'
28
+
29
+ client = Presto::Metrics::Client.new # Access to http://localhost:8080 in default
30
+
31
+ # Alternatively, you can specify the host name and port number to use
32
+ client = Presto::Metrics::Client.new(:host => "localhost", :port=>8081)
33
+
34
+
35
+ client.os_metrics
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"}
37
+
38
+ # This is equivalent to write as follows
39
+ client.get_metrics("java.lang:type=OperatingSystem")
40
+
41
+ # Retrieve a set of parameters
42
+ client.query_manager_metrics(["executor.active_count", "executor.completed_task_count"])
43
+ # => {:"executor.active_count"=>0, :"executor.completed_task_count"=>0}
44
+ client.os_metrics([:system_load_average, :free_physical_memory_size])
45
+ #=> {:free_physical_memory_size=>3690512384, :system_load_average=>2.33056640625}
46
+
47
+ # Retrieve standard metrics
48
+ client.memory_usage_metrics # java.lang:Type=Memory
49
+ client.os_metrics # java.lang:type=OperatingSystm
50
+ client.gc_cms_metrics # java.lang:type=GarbageCollector,name=ConcurrentMarkSweep
51
+ client.gc_parnew_metrics # java.lang:type=GarbageCollector,name=ParNew
52
+ client.query_manager_metrics # com.facebook.presto.execution:name=QueryManager
53
+ client.query_execution_metrics # com.facebook.presto.execution:name=QueryExecution
54
+ client.node_scheduler_metrics # com.facebook.presto.execution:name=NodeScheduler
55
+ client.task_executor_metrics # com.facebook.presto.execution:name=TaskExecutor
56
+ client.task_manager_metrics # com.facebook.presto.execution:name=TaskManager
57
+
58
+ # Retrieve the JSON representation of JMX properties
59
+ client.get_json("java.lang:Type=Memory")
60
+
61
+ ```
62
+
63
+ ## Contributing
64
+
65
+ 1. Fork it ( https://github.com/[my-github-username]/presto-metrics/fork )
66
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
67
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
68
+ 4. Push to the branch (`git push origin my-new-feature`)
69
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
@@ -0,0 +1,107 @@
1
+ require "presto/metrics/version"
2
+ require 'httparty'
3
+ require 'json'
4
+
5
+ module Presto
6
+ module Metrics
7
+
8
+ class Client
9
+ def initialize(opts={})
10
+ @host = opts[:host] || "localhost"
11
+ @port = opts[:port] || "8080"
12
+ @endpoint = opts[:endpoint] || "http://#{@host}:#{@port}"
13
+ @mbean_path = opts[:mbean_path] || "/v1/jmx/mbean/"
14
+ @caml_case = opts[:caml_case] || false
15
+ end
16
+
17
+ def get(mbean)
18
+ JSON.parse(get_json(mbean))
19
+ end
20
+
21
+ def get_json(mbean)
22
+ resp = HTTParty.get("#{@endpoint}#{@mbean_path}#{mbean}")
23
+ resp.body
24
+ end
25
+
26
+ def get_attributes(mbean)
27
+ json = get(mbean)
28
+ json['attributes'] || []
29
+ end
30
+
31
+ def get_attribute(mbean, attr_name)
32
+ get_attributes(mbean).find {|obj| obj['name'] == attr_name } || {}
33
+ end
34
+
35
+ def map_to_canonical_name(name_arr)
36
+ name_arr.map{|name| to_canonical_name(name) }
37
+ end
38
+
39
+ def to_canonical_name(name)
40
+ name.to_s.downcase.gsub(/_/, "")
41
+ end
42
+
43
+ def underscore(str)
44
+ str.gsub(/::/, '/').
45
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
46
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
47
+ tr("-", "_").
48
+ downcase
49
+ end
50
+
51
+ def get_metrics(mbean, target_attr=[])
52
+ kv = Hash.new
53
+ arr = target_attr.kind_of?(Array) ? target_attr : [target_attr]
54
+ c_target_attr = map_to_canonical_name(arr).to_set
55
+ get_attributes(mbean)
56
+ .reject {|attr| attr['name'].nil? || attr['value'].nil? }
57
+ .each {|attr|
58
+ c_name = to_canonical_name(attr['name'])
59
+ if c_target_attr.empty? || c_target_attr.include?(c_name)
60
+ key = @caml_case ? attr['name'] : underscore(attr['name']).to_sym
61
+ kv[key] = attr['value']
62
+ end
63
+ }
64
+ kv
65
+ end
66
+
67
+ def memory_usage_metrics(target_attr=[])
68
+ get_metrics("java.lang:type=Memory", target_attr)
69
+ end
70
+
71
+ def gc_cms_metrics(target_attr=[])
72
+ get_metrics("java.lang:type=GarbageCollector,name=ConcurrentMarkSweep", target_attr)
73
+ end
74
+
75
+ def gc_parnew_metrics(target_attr=[])
76
+ get_metrics("java.lang:type=GarbageCollector,name=ParNew", target_attr)
77
+ end
78
+
79
+ def os_metrics(target_attr=[])
80
+ get_metrics("java.lang:type=OperatingSystem", target_attr)
81
+ end
82
+
83
+ def query_manager_metrics(target_attr=[])
84
+ get_metrics("com.facebook.presto.execution:name=QueryManager", target_attr)
85
+ end
86
+
87
+ def query_execution_metrics(target_attr=[])
88
+ get_metrics("com.facebook.presto.execution:name=QueryExecution", target_attr)
89
+ end
90
+
91
+ def node_scheduler_metrics(target_attr=[])
92
+ get_metrics("com.facebook.presto.execution:name=NodeScheduler", target_attr)
93
+ end
94
+
95
+ def task_executor_metrics(target_attr=[])
96
+ get_metrics("com.facebook.presto.execution:name=TaskExecutor", target_attr)
97
+ end
98
+
99
+ def task_manager_metrics(target_attr=[])
100
+ get_metrics("com.facebook.presto.execution:name=TaskManager", target_attr)
101
+ end
102
+
103
+ private :map_to_canonical_name, :to_canonical_name, :underscore
104
+ end
105
+ end
106
+ end
107
+
@@ -0,0 +1,5 @@
1
+ module Presto
2
+ module Metrics
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'presto/metrics/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "presto-metrics"
8
+ spec.version = Presto::Metrics::VERSION
9
+ spec.authors = ["Taro L. Saito"]
10
+ spec.email = ["leo@xerial.org"]
11
+ spec.summary = "Presto metric collection library"
12
+ spec.description = "Library for collecting metrics through JMX REST API (/v1/jmx/mbean) of Presto"
13
+ spec.homepage = "https://github.com/xerial/presto-metrics"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Presto::Metrics do
4
+ it 'has a version number' do
5
+ expect(Presto::Metrics::VERSION).not_to be nil
6
+ end
7
+
8
+ it 'does something useful' do
9
+ expect(false).to eq(true)
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'presto/metrics'
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: presto-metrics
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Taro L. Saito
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Library for collecting metrics through JMX REST API (/v1/jmx/mbean) of
56
+ Presto
57
+ email:
58
+ - leo@xerial.org
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - .rspec
65
+ - .travis.yml
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - lib/presto/metrics.rb
71
+ - lib/presto/metrics/version.rb
72
+ - presto-metrics.gemspec
73
+ - spec/presto/metrics_spec.rb
74
+ - spec/spec_helper.rb
75
+ homepage: https://github.com/xerial/presto-metrics
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.0.14
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Presto metric collection library
99
+ test_files:
100
+ - spec/presto/metrics_spec.rb
101
+ - spec/spec_helper.rb