cube-evaluator 0.0.1.alpha

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cube-evaluator.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Matteo Depalo
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,52 @@
1
+ # Cube Evaluator
2
+
3
+ Obtain data from cube evaluators in a nice format
4
+
5
+ ## Installation
6
+
7
+ Add this to your Gemfile
8
+
9
+ ```ruby
10
+ gem cube-evaluator
11
+ ```
12
+
13
+ and then run
14
+
15
+ `bundle`
16
+
17
+ ## Usage
18
+
19
+ Configure the cube evaluator client
20
+
21
+ ```ruby
22
+ # use default hostname and port of localhost:1081
23
+ $cube_evaluator = Cube::Evaluator.new
24
+
25
+ # use custom hostname and port
26
+ $cube_evaluator = Cube::Evaluator.new 'cube.example.com', 2280
27
+ ```
28
+
29
+ Ask for some metrics
30
+
31
+ ```ruby
32
+ $cube_evaluator.metric(:expression => 'sum(request)', :start => Time.now - 2592000, :stop => Time.now, :limit => 10, :step => '1minute')
33
+ ```
34
+
35
+ The result will be a json encoded Hash with an array of 'times' and the corresponding 'values'
36
+
37
+ The supported steps are:
38
+
39
+ * 10seconds
40
+ * 1minute
41
+ * 5minutes
42
+ * 1hour
43
+ * 1day
44
+
45
+ For a complete guide on how to use the cube evaluator take a loot at:
46
+
47
+ https://github.com/square/cube/wiki/Evaluator
48
+
49
+ # TODO
50
+
51
+ * Add support for evaluator events and types
52
+ * Add tests
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: :spec
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/cube-evaluator/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Matteo Depalo"]
6
+ gem.email = ["matteodepalo@gmail.com"]
7
+ gem.description = %q{Square Cube evaluator gem}
8
+ gem.summary = %q{Ruby gem to obtain data from a Cube evaluator}
9
+ gem.homepage = "https://github.com/matteodepalo/cube-evaluator"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "cube-evaluator"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Cube::Evaluator::VERSION
17
+
18
+ gem.add_development_dependency 'rspec'
19
+ end
@@ -0,0 +1,60 @@
1
+ require "cube-evaluator/version"
2
+
3
+ module Cube
4
+ class Evaluator
5
+ def initialize(url = 'localhost', port = 1081)
6
+ @url = "http://#{url}:#{port}/1.0/metric/get"
7
+ end
8
+
9
+ def metric(options = {})
10
+ uri = URI(@url)
11
+
12
+ params = options.merge(options) do |k,v|
13
+ if v.is_a?(DateTime) || v.is_a?(Date) || v.is_a?(Time)
14
+ v.to_time.utc.iso8601
15
+ elsif k == :step
16
+ to_step(v)
17
+ else
18
+ v
19
+ end
20
+ end
21
+
22
+ uri.query = URI.encode_www_form(params)
23
+ res = Net::HTTP.get_response(uri)
24
+ json_res = JSON.parse(res.body)
25
+
26
+ json_res = json_res.map do |metric|
27
+ metric.merge(metric) { |k, v| k == 'time' ? Time.parse(v) : v }
28
+ end
29
+
30
+ result = { :times => [], :values => [] }
31
+
32
+ json_res.each do |metric|
33
+ metric.each do |k,v|
34
+ if k == 'time'
35
+ result[:times] << v
36
+ elsif k == 'value'
37
+ result[:values] << v
38
+ end
39
+ end
40
+ end
41
+
42
+ result
43
+ end
44
+
45
+ def to_step(step)
46
+ case step
47
+ when '10seconds'
48
+ '1e4'
49
+ when '1minute'
50
+ '6e4'
51
+ when '5minutes'
52
+ '3e5'
53
+ when '1hour'
54
+ '36e5'
55
+ when '1day'
56
+ '864e5'
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,5 @@
1
+ module Cube
2
+ module Evaluator
3
+ VERSION = "0.0.1.alpha"
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Cube::Evaluator do
4
+
5
+ end
@@ -0,0 +1 @@
1
+ require 'cube-evaluator'
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cube-evaluator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.alpha
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Matteo Depalo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Square Cube evaluator gem
31
+ email:
32
+ - matteodepalo@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE
40
+ - README.md
41
+ - Rakefile
42
+ - cube-evaluator.gemspec
43
+ - lib/cube-evaluator.rb
44
+ - lib/cube-evaluator/version.rb
45
+ - spec/cube-evaluator_spec.rb
46
+ - spec/spec_helper.rb
47
+ homepage: https://github.com/matteodepalo/cube-evaluator
48
+ licenses: []
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>'
63
+ - !ruby/object:Gem::Version
64
+ version: 1.3.1
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 1.8.24
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Ruby gem to obtain data from a Cube evaluator
71
+ test_files:
72
+ - spec/cube-evaluator_spec.rb
73
+ - spec/spec_helper.rb