opentsdb-consumer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/.travis.yml +8 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +95 -0
- data/LICENSE.txt +20 -0
- data/README.md +20 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/bin/opentsdb-consumer +22 -0
- data/lib/opentsdb-consumer/client.rb +21 -0
- data/lib/opentsdb-consumer/errors.rb +3 -0
- data/lib/opentsdb-consumer/metric.rb +27 -0
- data/lib/opentsdb-consumer/query.rb +20 -0
- data/lib/opentsdb-consumer/result.rb +17 -0
- data/lib/opentsdb-consumer.rb +8 -0
- data/opentsdb-consumer.gemspec +84 -0
- data/spec/opentsdb-consumer/client_spec.rb +12 -0
- data/spec/opentsdb-consumer/metric_spec.rb +28 -0
- data/spec/opentsdb-consumer/query_spec.rb +44 -0
- data/spec/opentsdb-consumer/result_spec.rb +33 -0
- data/spec/spec_helper.rb +28 -0
- metadata +180 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5d8761a3f012b2dd284afe03ec8b667049394bf4
|
4
|
+
data.tar.gz: 176850b0278e299ce20e4f1b9dbd3922147f663b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8950d70d7fa8105c840827a434b6917b03cf93524314e1a991562b972581f94bfd498276c0f08417ea4608c338d12a21aeda20745c0a3aef7d0480a646272c40
|
7
|
+
data.tar.gz: 33753e8a302fbb0414e9b4be586017db0b0eb5333348a7dfcecd746a3efa84a45b9626d9c31d08427aeeddf48fbd31fde29ead92d83b40fdbd89e90c15904727
|
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
gem 'excon', '~> 0.45.0'
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
gem 'rspec', '~> 3.3.0'
|
7
|
+
gem 'rdoc', '~> 3.12'
|
8
|
+
gem 'bundler', '~> 1.0'
|
9
|
+
gem 'jeweler', '~> 2.0.1'
|
10
|
+
gem 'simplecov', '>= 0'
|
11
|
+
|
12
|
+
gem 'byebug'
|
13
|
+
gem 'pry'
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.3.8)
|
5
|
+
builder (3.2.2)
|
6
|
+
byebug (5.0.0)
|
7
|
+
columnize (= 0.9.0)
|
8
|
+
coderay (1.1.0)
|
9
|
+
columnize (0.9.0)
|
10
|
+
descendants_tracker (0.0.4)
|
11
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
12
|
+
diff-lcs (1.2.5)
|
13
|
+
docile (1.1.5)
|
14
|
+
excon (0.45.4)
|
15
|
+
faraday (0.9.1)
|
16
|
+
multipart-post (>= 1.2, < 3)
|
17
|
+
git (1.2.9.1)
|
18
|
+
github_api (0.12.4)
|
19
|
+
addressable (~> 2.3)
|
20
|
+
descendants_tracker (~> 0.0.4)
|
21
|
+
faraday (~> 0.8, < 0.10)
|
22
|
+
hashie (>= 3.4)
|
23
|
+
multi_json (>= 1.7.5, < 2.0)
|
24
|
+
nokogiri (~> 1.6.6)
|
25
|
+
oauth2
|
26
|
+
hashie (3.4.2)
|
27
|
+
highline (1.7.3)
|
28
|
+
jeweler (2.0.1)
|
29
|
+
builder
|
30
|
+
bundler (>= 1.0)
|
31
|
+
git (>= 1.2.5)
|
32
|
+
github_api
|
33
|
+
highline (>= 1.6.15)
|
34
|
+
nokogiri (>= 1.5.10)
|
35
|
+
rake
|
36
|
+
rdoc
|
37
|
+
json (1.8.3)
|
38
|
+
jwt (1.5.1)
|
39
|
+
method_source (0.8.2)
|
40
|
+
mini_portile (0.6.2)
|
41
|
+
multi_json (1.11.2)
|
42
|
+
multi_xml (0.5.5)
|
43
|
+
multipart-post (2.0.0)
|
44
|
+
nokogiri (1.6.6.2)
|
45
|
+
mini_portile (~> 0.6.0)
|
46
|
+
oauth2 (1.0.0)
|
47
|
+
faraday (>= 0.8, < 0.10)
|
48
|
+
jwt (~> 1.0)
|
49
|
+
multi_json (~> 1.3)
|
50
|
+
multi_xml (~> 0.5)
|
51
|
+
rack (~> 1.2)
|
52
|
+
pry (0.10.1)
|
53
|
+
coderay (~> 1.1.0)
|
54
|
+
method_source (~> 0.8.1)
|
55
|
+
slop (~> 3.4)
|
56
|
+
rack (1.6.4)
|
57
|
+
rake (10.4.2)
|
58
|
+
rdoc (3.12.2)
|
59
|
+
json (~> 1.4)
|
60
|
+
rspec (3.3.0)
|
61
|
+
rspec-core (~> 3.3.0)
|
62
|
+
rspec-expectations (~> 3.3.0)
|
63
|
+
rspec-mocks (~> 3.3.0)
|
64
|
+
rspec-core (3.3.1)
|
65
|
+
rspec-support (~> 3.3.0)
|
66
|
+
rspec-expectations (3.3.0)
|
67
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
68
|
+
rspec-support (~> 3.3.0)
|
69
|
+
rspec-mocks (3.3.1)
|
70
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
71
|
+
rspec-support (~> 3.3.0)
|
72
|
+
rspec-support (3.3.0)
|
73
|
+
simplecov (0.10.0)
|
74
|
+
docile (~> 1.1.0)
|
75
|
+
json (~> 1.8)
|
76
|
+
simplecov-html (~> 0.10.0)
|
77
|
+
simplecov-html (0.10.0)
|
78
|
+
slop (3.6.0)
|
79
|
+
thread_safe (0.3.5)
|
80
|
+
|
81
|
+
PLATFORMS
|
82
|
+
ruby
|
83
|
+
|
84
|
+
DEPENDENCIES
|
85
|
+
bundler (~> 1.0)
|
86
|
+
byebug
|
87
|
+
excon (~> 0.45.0)
|
88
|
+
jeweler (~> 2.0.1)
|
89
|
+
pry
|
90
|
+
rdoc (~> 3.12)
|
91
|
+
rspec (~> 3.3.0)
|
92
|
+
simplecov
|
93
|
+
|
94
|
+
BUNDLED WITH
|
95
|
+
1.10.6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2015 nine.ch
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
opentsdb-consumer [![Build Status](https://travis-ci.org/ninech/opentsdb-consumer.svg)](https://travis-ci.org/ninech/opentsdb-consumer)
|
2
|
+
=================
|
3
|
+
|
4
|
+
Client library to fetch metrics from OpenTSDB.
|
5
|
+
|
6
|
+
## Contributing to opentsdb-consumer
|
7
|
+
|
8
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
9
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
10
|
+
* Fork the project.
|
11
|
+
* Start a feature/bugfix branch.
|
12
|
+
* Commit and push until you are happy with your contribution.
|
13
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
14
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
15
|
+
|
16
|
+
## Copyright
|
17
|
+
|
18
|
+
Copyright (c) 2015 Nine Internet Solutions AG. See LICENSE.txt for
|
19
|
+
further details.
|
20
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts 'Run `bundle install` to install missing gems'
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
17
|
+
gem.name = 'opentsdb-consumer'
|
18
|
+
gem.homepage = 'http://github.com/ninech/opentsdb-consumer'
|
19
|
+
gem.license = 'MIT'
|
20
|
+
gem.summary = %(Client library to consume metrics from OpenTSDB)
|
21
|
+
gem.description = %(Client library to consume metrics from OpenTSDB)
|
22
|
+
gem.email = 'phil@nine.ch'
|
23
|
+
gem.authors = ['Philippe Hässig']
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
desc 'Code coverage detail'
|
35
|
+
task :simplecov do
|
36
|
+
ENV['COVERAGE'] = 'true'
|
37
|
+
Rake::Task['spec'].execute
|
38
|
+
end
|
39
|
+
|
40
|
+
task default: :spec
|
41
|
+
|
42
|
+
require 'rdoc/task'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ''
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "opentsdb-consumer #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
APP_ROOT = File.join(File.dirname(Pathname.new(__FILE__).realpath), '..')
|
6
|
+
|
7
|
+
$LOAD_PATH.unshift File.join(APP_ROOT, 'lib')
|
8
|
+
|
9
|
+
require 'bundler/setup'
|
10
|
+
require 'pry'
|
11
|
+
require 'opentsdb-consumer'
|
12
|
+
|
13
|
+
if ARGV.empty?
|
14
|
+
puts 'Usage: bin/opentsdb-consumer <hostname> <metric>'
|
15
|
+
exit 0
|
16
|
+
end
|
17
|
+
|
18
|
+
client = OpenTSDBConsumer::Client.new host: ARGV[0]
|
19
|
+
metric = OpenTSDBConsumer::Metric.new name: ARGV[1]
|
20
|
+
query = OpenTSDBConsumer::Query.new metric, client
|
21
|
+
|
22
|
+
binding.pry
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'excon'
|
2
|
+
|
3
|
+
module OpenTSDBConsumer
|
4
|
+
class Client
|
5
|
+
attr_reader :host, :port, :connection
|
6
|
+
|
7
|
+
def initialize(host: 'localhost', port: 4242, options: {})
|
8
|
+
@host = host
|
9
|
+
@port = port
|
10
|
+
@connection = Excon.new url, options
|
11
|
+
end
|
12
|
+
|
13
|
+
def get(params)
|
14
|
+
connection.get params
|
15
|
+
end
|
16
|
+
|
17
|
+
def url
|
18
|
+
"http://#{host}:#{port}/api/query"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module OpenTSDBConsumer
|
2
|
+
class Metric
|
3
|
+
attr_reader :name, :aggregator, :rate, :tags
|
4
|
+
|
5
|
+
def initialize(name: nil, aggregator: 'sum', rate: false, tags: {})
|
6
|
+
@name = name
|
7
|
+
@aggregator = aggregator
|
8
|
+
@rate = rate
|
9
|
+
@tags = tags
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
query = tags.any? ? "{#{tags_to_query}}" : ''
|
14
|
+
[aggregator, rate_to_query, name].compact.join(':') + query
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def tags_to_query
|
20
|
+
tags.map { |key, value| [key, value].join '=' }.join(',')
|
21
|
+
end
|
22
|
+
|
23
|
+
def rate_to_query
|
24
|
+
'rate' if rate
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module OpenTSDBConsumer
|
4
|
+
class Query
|
5
|
+
attr_accessor :metric, :client
|
6
|
+
|
7
|
+
def initialize(metric, client)
|
8
|
+
@metric = metric
|
9
|
+
@client = client
|
10
|
+
end
|
11
|
+
|
12
|
+
def run(start: '1h-ago')
|
13
|
+
response = client.get query: { m: metric, start: start }
|
14
|
+
parsed_body = JSON.parse(response.body)
|
15
|
+
return OpenTSDBConsumer::Result.build(parsed_body) if response.status < 400
|
16
|
+
|
17
|
+
fail QueryError, parsed_body['error']['message']
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module OpenTSDBConsumer
|
2
|
+
class Result
|
3
|
+
attr_reader :metric_name, :tags, :aggregate_tags, :datapoints
|
4
|
+
|
5
|
+
def initialize(response)
|
6
|
+
@metric_name = response['metric']
|
7
|
+
@tags = response['tags']
|
8
|
+
@aggregate_tags = response['aggregateTags']
|
9
|
+
@datapoints = response['dps']
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.build(response)
|
13
|
+
results = response.map { |h| new(h) }
|
14
|
+
results.length > 1 ? results : results.first
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: opentsdb-consumer 0.1.0 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "opentsdb-consumer"
|
9
|
+
s.version = "0.1.0"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.authors = ["Philippe H\u{e4}ssig"]
|
14
|
+
s.date = "2015-09-10"
|
15
|
+
s.description = "Client library to consume metrics from OpenTSDB"
|
16
|
+
s.email = "phil@nine.ch"
|
17
|
+
s.executables = ["opentsdb-consumer"]
|
18
|
+
s.extra_rdoc_files = [
|
19
|
+
"LICENSE.txt",
|
20
|
+
"README.md"
|
21
|
+
]
|
22
|
+
s.files = [
|
23
|
+
".document",
|
24
|
+
".rspec",
|
25
|
+
".travis.yml",
|
26
|
+
"Gemfile",
|
27
|
+
"Gemfile.lock",
|
28
|
+
"LICENSE.txt",
|
29
|
+
"README.md",
|
30
|
+
"Rakefile",
|
31
|
+
"VERSION",
|
32
|
+
"bin/opentsdb-consumer",
|
33
|
+
"lib/opentsdb-consumer.rb",
|
34
|
+
"lib/opentsdb-consumer/client.rb",
|
35
|
+
"lib/opentsdb-consumer/errors.rb",
|
36
|
+
"lib/opentsdb-consumer/metric.rb",
|
37
|
+
"lib/opentsdb-consumer/query.rb",
|
38
|
+
"lib/opentsdb-consumer/result.rb",
|
39
|
+
"opentsdb-consumer.gemspec",
|
40
|
+
"spec/opentsdb-consumer/client_spec.rb",
|
41
|
+
"spec/opentsdb-consumer/metric_spec.rb",
|
42
|
+
"spec/opentsdb-consumer/query_spec.rb",
|
43
|
+
"spec/opentsdb-consumer/result_spec.rb",
|
44
|
+
"spec/spec_helper.rb"
|
45
|
+
]
|
46
|
+
s.homepage = "http://github.com/ninech/opentsdb-consumer"
|
47
|
+
s.licenses = ["MIT"]
|
48
|
+
s.rubygems_version = "2.4.5"
|
49
|
+
s.summary = "Client library to consume metrics from OpenTSDB"
|
50
|
+
|
51
|
+
if s.respond_to? :specification_version then
|
52
|
+
s.specification_version = 4
|
53
|
+
|
54
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
55
|
+
s.add_runtime_dependency(%q<excon>, ["~> 0.45.0"])
|
56
|
+
s.add_development_dependency(%q<rspec>, ["~> 3.3.0"])
|
57
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
58
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
59
|
+
s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
|
60
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
61
|
+
s.add_development_dependency(%q<byebug>, [">= 0"])
|
62
|
+
s.add_development_dependency(%q<pry>, [">= 0"])
|
63
|
+
else
|
64
|
+
s.add_dependency(%q<excon>, ["~> 0.45.0"])
|
65
|
+
s.add_dependency(%q<rspec>, ["~> 3.3.0"])
|
66
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
67
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
68
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
69
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
70
|
+
s.add_dependency(%q<byebug>, [">= 0"])
|
71
|
+
s.add_dependency(%q<pry>, [">= 0"])
|
72
|
+
end
|
73
|
+
else
|
74
|
+
s.add_dependency(%q<excon>, ["~> 0.45.0"])
|
75
|
+
s.add_dependency(%q<rspec>, ["~> 3.3.0"])
|
76
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
77
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
78
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
79
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
80
|
+
s.add_dependency(%q<byebug>, [">= 0"])
|
81
|
+
s.add_dependency(%q<pry>, [">= 0"])
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'opentsdb-consumer/client'
|
3
|
+
|
4
|
+
RSpec.describe OpenTSDBConsumer::Client do
|
5
|
+
let(:client) { described_class.new host: 'metrics.local', port: '4243' }
|
6
|
+
|
7
|
+
describe '#url' do
|
8
|
+
it 'assembles a correct url for opentsdb requests' do
|
9
|
+
expect(client.url).to eq 'http://metrics.local:4243/api/query'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'opentsdb-consumer/metric'
|
3
|
+
|
4
|
+
RSpec.describe OpenTSDBConsumer::Metric do
|
5
|
+
let(:name) { 'my.metric' }
|
6
|
+
let(:aggregator) { 'avg' }
|
7
|
+
let(:rate) { false }
|
8
|
+
let(:tags) { {} }
|
9
|
+
let(:metric) { described_class.new name: name, aggregator: aggregator, rate: rate, tags: tags }
|
10
|
+
|
11
|
+
describe '#to_s' do
|
12
|
+
subject { metric.to_s }
|
13
|
+
|
14
|
+
context 'without tags' do
|
15
|
+
it { should eq 'avg:my.metric' }
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'with tags' do
|
19
|
+
let(:tags) { { host: 'metrics01', cpu: 0 } }
|
20
|
+
it { should eq 'avg:my.metric{host=metrics01,cpu=0}' }
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'with rate' do
|
24
|
+
let(:rate) { true }
|
25
|
+
it { should eq 'avg:rate:my.metric' }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe OpenTSDBConsumer::Query do
|
4
|
+
let(:metric) { OpenTSDBConsumer::Metric.new name: 'my.metric' }
|
5
|
+
let(:client) { instance_double 'OpenTSDBConsumer::Client', get: mock_response }
|
6
|
+
let(:query) { described_class.new metric, client }
|
7
|
+
let(:status) { 200 }
|
8
|
+
let(:response_body) { '[{}]' }
|
9
|
+
let(:mock_response) { instance_double 'Excon::Response', status: status, body: response_body }
|
10
|
+
|
11
|
+
describe '#run' do
|
12
|
+
context 'successfuly' do
|
13
|
+
it 'queries the server for the given metric' do
|
14
|
+
expect(client).to receive(:get).
|
15
|
+
with(query: { m: metric, start: '1h-ago' }).
|
16
|
+
and_return(mock_response)
|
17
|
+
query.run
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'allows to set a start time' do
|
21
|
+
expect(client).to receive(:get).
|
22
|
+
with(query: { m: metric, start: '24h-ago' }).
|
23
|
+
and_return(mock_response)
|
24
|
+
query.run start: '24h-ago'
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'returns the parsed body' do
|
28
|
+
expect(client).to receive(:get).and_return(mock_response)
|
29
|
+
expect(query.run).to be_a OpenTSDBConsumer::Result
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'invalid metric' do
|
34
|
+
let(:status) { 400 }
|
35
|
+
let(:response_body) do
|
36
|
+
%({"error":{"code":400,"message":"No such name for 'metrics': '#{metric.name}'"}})
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'raises an error' do
|
40
|
+
expect { query.run }.to raise_exception OpenTSDBConsumer::QueryError
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'opentsdb-consumer/result'
|
3
|
+
|
4
|
+
RSpec.describe OpenTSDBConsumer::Result do
|
5
|
+
describe '.initialize' do
|
6
|
+
it 'initializes all variables' do
|
7
|
+
result = described_class.new 'metric' => 'my.metric',
|
8
|
+
'tags' => {},
|
9
|
+
'aggregateTags' => [],
|
10
|
+
'dps' => [{ '1': 2 }]
|
11
|
+
|
12
|
+
expect(result.metric_name).to eq 'my.metric'
|
13
|
+
expect(result.tags).to eq({})
|
14
|
+
expect(result.aggregate_tags).to eq []
|
15
|
+
expect(result.datapoints).to eq [{ '1': 2 }]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '.build' do
|
20
|
+
it 'builds a result object from a query response' do
|
21
|
+
response = [{}]
|
22
|
+
expect(described_class.build(response)).to be_a OpenTSDBConsumer::Result
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'returns an array of result objects when there are many' do
|
26
|
+
response = [{}, {}]
|
27
|
+
results = described_class.build(response)
|
28
|
+
expect(results).to be_a Array
|
29
|
+
expect(results.first).to be_a OpenTSDBConsumer::Result
|
30
|
+
expect(results.last).to be_a OpenTSDBConsumer::Result
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
module SimpleCov::Configuration
|
4
|
+
def clean_filters
|
5
|
+
@filters = []
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
SimpleCov.configure do
|
10
|
+
clean_filters
|
11
|
+
load_profile 'root_filter'
|
12
|
+
end
|
13
|
+
|
14
|
+
ENV['COVERAGE'] && SimpleCov.start do
|
15
|
+
end
|
16
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
17
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
18
|
+
|
19
|
+
require 'rspec'
|
20
|
+
require 'opentsdb-consumer'
|
21
|
+
|
22
|
+
# Requires supporting files with custom matchers and macros, etc,
|
23
|
+
# in ./support/ and its subdirectories.
|
24
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
25
|
+
|
26
|
+
RSpec.configure do |config|
|
27
|
+
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: opentsdb-consumer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Philippe Hässig
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: excon
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.45.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.45.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.3.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.3.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rdoc
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.12'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.12'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: jeweler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.0.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.0.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: byebug
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: Client library to consume metrics from OpenTSDB
|
126
|
+
email: phil@nine.ch
|
127
|
+
executables:
|
128
|
+
- opentsdb-consumer
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files:
|
131
|
+
- LICENSE.txt
|
132
|
+
- README.md
|
133
|
+
files:
|
134
|
+
- ".document"
|
135
|
+
- ".rspec"
|
136
|
+
- ".travis.yml"
|
137
|
+
- Gemfile
|
138
|
+
- Gemfile.lock
|
139
|
+
- LICENSE.txt
|
140
|
+
- README.md
|
141
|
+
- Rakefile
|
142
|
+
- VERSION
|
143
|
+
- bin/opentsdb-consumer
|
144
|
+
- lib/opentsdb-consumer.rb
|
145
|
+
- lib/opentsdb-consumer/client.rb
|
146
|
+
- lib/opentsdb-consumer/errors.rb
|
147
|
+
- lib/opentsdb-consumer/metric.rb
|
148
|
+
- lib/opentsdb-consumer/query.rb
|
149
|
+
- lib/opentsdb-consumer/result.rb
|
150
|
+
- opentsdb-consumer.gemspec
|
151
|
+
- spec/opentsdb-consumer/client_spec.rb
|
152
|
+
- spec/opentsdb-consumer/metric_spec.rb
|
153
|
+
- spec/opentsdb-consumer/query_spec.rb
|
154
|
+
- spec/opentsdb-consumer/result_spec.rb
|
155
|
+
- spec/spec_helper.rb
|
156
|
+
homepage: http://github.com/ninech/opentsdb-consumer
|
157
|
+
licenses:
|
158
|
+
- MIT
|
159
|
+
metadata: {}
|
160
|
+
post_install_message:
|
161
|
+
rdoc_options: []
|
162
|
+
require_paths:
|
163
|
+
- lib
|
164
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
requirements: []
|
175
|
+
rubyforge_project:
|
176
|
+
rubygems_version: 2.4.5
|
177
|
+
signing_key:
|
178
|
+
specification_version: 4
|
179
|
+
summary: Client library to consume metrics from OpenTSDB
|
180
|
+
test_files: []
|