opentsdb-consumer 0.4.0 → 0.5.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: a78304f73686cf40a865ef0546337c5b11a69847
4
- data.tar.gz: f216a7b347b229066c52ab2dd04d5a9ef272ffad
3
+ metadata.gz: 334956afe7507b50e68bdb15ee3fb1259e308c9a
4
+ data.tar.gz: 39e5074094710e559e0354f8eb6fd941b653f838
5
5
  SHA512:
6
- metadata.gz: 853a0322f569c5efc7818d1a2ea2e03b6903059cce7707a0f13dad2ba6e3de41b69a23957c310f2fec7e51831b8e51b60bc42824d6a1c42731ae89579451721d
7
- data.tar.gz: cb611732fbd5b61b6cb53cd7afa54d7feb48a5c71079baa552728a6777ff12550058857fd0b59bfb20b5bd9283a005f50f27baa804ab7d5e3cd0d8805e863298
6
+ metadata.gz: 04482b0690cc6e8b86e09300c17f10f5a999cb20e56fd6cf326aca2c191e633e65f5e8a5b63313d1d802c771dcf98487869eb3dff07cf082f77cd76ce63697d4
7
+ data.tar.gz: 16b717f60281eed71d6c8ec0e93b8661e63889576cb93564862d0fc87e1862df872fb8cef57f1da1a988502c7388d9f196bfc3b7e5dd6c411c5742f2b4233131
data/.gitignore ADDED
@@ -0,0 +1,49 @@
1
+ # rcov generated
2
+ coverage
3
+ coverage.data
4
+
5
+ # rdoc generated
6
+ rdoc
7
+
8
+ # yard generated
9
+ doc
10
+ .yardoc
11
+
12
+ # bundler
13
+ .bundle
14
+
15
+ # jeweler generated
16
+ pkg
17
+
18
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
19
+ #
20
+ # * Create a file at ~/.gitignore
21
+ # * Include files you want ignored
22
+ # * Run: git config --global core.excludesfile ~/.gitignore
23
+ #
24
+ # After doing this, these files will be ignored in all your git projects,
25
+ # saving you from having to 'pollute' every project you touch with them
26
+ #
27
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
28
+ #
29
+ # For MacOS:
30
+ #
31
+ #.DS_Store
32
+
33
+ # For TextMate
34
+ #*.tmproj
35
+ #tmtags
36
+
37
+ # For emacs:
38
+ #*~
39
+ #\#*
40
+ #.\#*
41
+
42
+ # For vim:
43
+ #*.swp
44
+
45
+ # For redcar:
46
+ #.redcar
47
+
48
+ # For rubinius:
49
+ #*.rbc
data/README.md CHANGED
@@ -23,6 +23,14 @@ metric = OpenTSDBConsumer::Metric.new name: 'my.metric', rate: true, aggregator:
23
23
  OpenTSDBConsumer::Query.new([metric], client).run start: '24h-ago'
24
24
  ```
25
25
 
26
+ The rate can be configured by providing an hash with the rate options.
27
+ ```ruby
28
+ metric = OpenTSDBConsumer::Metric.new name: 'my.metric',
29
+ rate: { counter: true, counterMax: 65535, resetValue: 2000 },
30
+ aggregator: 'sum'
31
+ ```
32
+
33
+
26
34
  ## Contributing to opentsdb-consumer
27
35
 
28
36
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.0
@@ -4,5 +4,6 @@ end
4
4
  require 'opentsdb-consumer/errors'
5
5
  require 'opentsdb-consumer/client'
6
6
  require 'opentsdb-consumer/metric'
7
+ require 'opentsdb-consumer/rate'
7
8
  require 'opentsdb-consumer/query'
8
9
  require 'opentsdb-consumer/result'
@@ -1,3 +1,5 @@
1
+ require 'opentsdb-consumer/rate'
2
+
1
3
  module OpenTSDBConsumer
2
4
  class Metric
3
5
  attr_reader :name, :aggregator, :rate, :downsample, :tags
@@ -5,24 +7,26 @@ module OpenTSDBConsumer
5
7
  def initialize(name: nil, aggregator: 'sum', rate: false, downsample: '10m-avg', tags: {})
6
8
  @name = name
7
9
  @aggregator = aggregator
8
- @rate = rate
10
+ @rate = Rate.new(rate) if rate
9
11
  @downsample = downsample
10
12
  @tags = tags
11
13
  end
12
14
 
13
15
  def to_s
14
16
  query = tags.any? ? "{#{tags_to_query}}" : ''
15
- [aggregator, downsample, rate_to_query, name].compact.join(':') + query
17
+ query += ":#{rate}" if rate
18
+ [aggregator, downsample, name].compact.join(':') + query
16
19
  end
17
20
 
18
21
  def to_h
19
- {
22
+ hash = {
20
23
  aggregator: aggregator,
21
24
  downsample: downsample,
22
25
  metric: name,
23
- rate: rate,
24
26
  tags: tags,
25
27
  }
28
+ hash.merge! rate.to_h if rate
29
+ hash
26
30
  end
27
31
 
28
32
  private
@@ -30,9 +34,5 @@ module OpenTSDBConsumer
30
34
  def tags_to_query
31
35
  tags.map { |key, value| [key, value].join '=' }.join(',')
32
36
  end
33
-
34
- def rate_to_query
35
- 'rate' if rate
36
- end
37
37
  end
38
38
  end
@@ -0,0 +1,28 @@
1
+ module OpenTSDBConsumer
2
+ class Rate
3
+ attr_reader :options
4
+
5
+ def initialize(options_or_true = {})
6
+ @options = options_or_true.is_a?(Hash) ? options_or_true : {}
7
+ end
8
+
9
+ def to_h
10
+ hash = { rate: true }
11
+ hash[:rateOptions] = options if options.any?
12
+ hash
13
+ end
14
+
15
+ def to_s
16
+ string = 'rate'
17
+ string += ":rateOptions{#{compiled_options}}" if options.any?
18
+ string
19
+ end
20
+
21
+ private
22
+
23
+ def compiled_options
24
+ return '' if options.empty?
25
+ options.map { |key, value| [key, value].join '=' }.join(',')
26
+ end
27
+ end
28
+ end
@@ -1,84 +1,28 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
5
- # stub: opentsdb-consumer 0.4.0 ruby lib
2
+ #
3
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
6
4
 
7
5
  Gem::Specification.new do |s|
8
- s.name = "opentsdb-consumer"
9
- s.version = "0.4.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 = "2016-01-13"
6
+ s.name = 'opentsdb-consumer'
7
+ s.version = File.read(File.expand_path('../VERSION', __FILE__)).strip
8
+ s.authors = ['Philippe Hassig']
9
+ s.email = ['phil@nine.ch']
10
+ s.homepage = 'http://github.com/ninech/'
11
+ s.license = 'MIT'
12
+ s.summary = "Client library to consume metrics from OpenTSDB"
15
13
  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.1"
49
- s.summary = "Client library to consume metrics from OpenTSDB"
50
14
 
51
- if s.respond_to? :specification_version then
52
- s.specification_version = 4
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
18
+ s.require_paths = ['lib']
53
19
 
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<byebug>, [">= 0"])
61
- s.add_development_dependency(%q<pry>, [">= 0"])
62
- s.add_development_dependency(%q<coveralls>, [">= 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<byebug>, [">= 0"])
70
- s.add_dependency(%q<pry>, [">= 0"])
71
- s.add_dependency(%q<coveralls>, [">= 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<byebug>, [">= 0"])
80
- s.add_dependency(%q<pry>, [">= 0"])
81
- s.add_dependency(%q<coveralls>, [">= 0"])
82
- end
83
- end
20
+ s.add_runtime_dependency 'excon', '~> 0.45.0'
84
21
 
22
+ s.add_development_dependency 'rspec', '~> 3.3', '>= 3.3.0'
23
+ s.add_development_dependency 'rdoc', '~> 3.12'
24
+ s.add_development_dependency 'bundler', '~> 1.0'
25
+ s.add_development_dependency 'byebug', '~> 0'
26
+ s.add_development_dependency 'pry', '~> 0'
27
+ s.add_development_dependency 'coveralls', '~> 0'
28
+ end
@@ -1,14 +1,20 @@
1
1
  require 'spec_helper'
2
2
  require 'opentsdb-consumer/metric'
3
+ require 'opentsdb-consumer/rate'
3
4
 
4
5
  RSpec.describe OpenTSDBConsumer::Metric do
5
6
  let(:name) { 'my.metric' }
6
7
  let(:aggregator) { 'avg' }
7
8
  let(:rate) { false }
8
9
  let(:tags) { {} }
10
+ let(:rate) { false }
9
11
  let(:downsample) { '1h-avg' }
10
12
  let(:metric) do
11
- described_class.new name: name, aggregator: aggregator, rate: rate, tags: tags, downsample: downsample
13
+ described_class.new name: name,
14
+ aggregator: aggregator,
15
+ rate: rate,
16
+ tags: tags,
17
+ downsample: downsample
12
18
  end
13
19
 
14
20
  describe '#to_s' do
@@ -24,14 +30,34 @@ RSpec.describe OpenTSDBConsumer::Metric do
24
30
  end
25
31
 
26
32
  context 'with rate' do
27
- let(:rate) { true }
28
- it { should eq 'avg:1h-avg:rate:my.metric' }
33
+ let(:rate) { { counter: true } }
34
+ it { should eq 'avg:1h-avg:my.metric:rate:rateOptions{counter=true}' }
29
35
  end
30
36
  end
31
37
 
32
38
  describe '#to_h' do
33
39
  subject { metric.to_h }
34
40
 
35
- it { should eq(aggregator: aggregator, downsample: downsample, metric: name, rate: rate, tags: tags) }
41
+ it do
42
+ should eq(aggregator: aggregator,
43
+ downsample: downsample,
44
+ metric: name,
45
+ tags: tags)
46
+ end
47
+
48
+ context 'with rate options' do
49
+ let(:rate) { { counter: true } }
50
+
51
+ it do
52
+ should eq(aggregator: aggregator,
53
+ downsample: downsample,
54
+ metric: name,
55
+ rate: true,
56
+ rateOptions: {
57
+ counter: true
58
+ },
59
+ tags: tags)
60
+ end
61
+ end
36
62
  end
37
63
  end
@@ -8,7 +8,7 @@ RSpec.describe OpenTSDBConsumer::Query do
8
8
  let(:response_body) { '[{}]' }
9
9
  let(:mock_response) { instance_double 'Excon::Response', status: status, body: response_body }
10
10
  let(:expected_query) do
11
- { aggregator: 'sum', downsample: '10m-avg', metric: 'my.metric', rate: false, tags: {} }
11
+ { aggregator: 'sum', downsample: '10m-avg', metric: 'my.metric', tags: {} }
12
12
  end
13
13
 
14
14
  describe '#run' do
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+ require 'opentsdb-consumer/rate'
3
+
4
+ RSpec.describe OpenTSDBConsumer::Rate do
5
+ describe '#to_s' do
6
+ subject { described_class.new(options).to_s }
7
+
8
+ context 'without options' do
9
+ let(:options) { {} }
10
+
11
+ it { should eq 'rate' }
12
+ end
13
+
14
+ context 'with options' do
15
+ let(:options) { { counter: true, counterMax: 1337 } }
16
+
17
+ it { should eq 'rate:rateOptions{counter=true,counterMax=1337}' }
18
+ end
19
+ end
20
+
21
+ describe '#to_h' do
22
+ let(:options) { {} }
23
+
24
+ subject { described_class.new(options).to_h }
25
+
26
+ it { should eq({ rate: true }) }
27
+
28
+ context 'with options' do
29
+ let(:options) { { counter: true, counterMax: 1337, resetValue: 100 } }
30
+
31
+ it do
32
+ should eq ({
33
+ rate: true,
34
+ rateOptions: options,
35
+ })
36
+ end
37
+ end
38
+ end
39
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentsdb-consumer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
- - Philippe Hässig
7
+ - Philippe Hassig
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-13 00:00:00.000000000 Z
11
+ date: 2016-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -29,6 +29,9 @@ dependencies:
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.3'
34
+ - - ">="
32
35
  - !ruby/object:Gem::Version
33
36
  version: 3.3.0
34
37
  type: :development
@@ -36,6 +39,9 @@ dependencies:
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
41
  - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '3.3'
44
+ - - ">="
39
45
  - !ruby/object:Gem::Version
40
46
  version: 3.3.0
41
47
  - !ruby/object:Gem::Dependency
@@ -66,72 +72,58 @@ dependencies:
66
72
  - - "~>"
67
73
  - !ruby/object:Gem::Version
68
74
  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
75
  - !ruby/object:Gem::Dependency
84
76
  name: byebug
85
77
  requirement: !ruby/object:Gem::Requirement
86
78
  requirements:
87
- - - ">="
79
+ - - "~>"
88
80
  - !ruby/object:Gem::Version
89
81
  version: '0'
90
82
  type: :development
91
83
  prerelease: false
92
84
  version_requirements: !ruby/object:Gem::Requirement
93
85
  requirements:
94
- - - ">="
86
+ - - "~>"
95
87
  - !ruby/object:Gem::Version
96
88
  version: '0'
97
89
  - !ruby/object:Gem::Dependency
98
90
  name: pry
99
91
  requirement: !ruby/object:Gem::Requirement
100
92
  requirements:
101
- - - ">="
93
+ - - "~>"
102
94
  - !ruby/object:Gem::Version
103
95
  version: '0'
104
96
  type: :development
105
97
  prerelease: false
106
98
  version_requirements: !ruby/object:Gem::Requirement
107
99
  requirements:
108
- - - ">="
100
+ - - "~>"
109
101
  - !ruby/object:Gem::Version
110
102
  version: '0'
111
103
  - !ruby/object:Gem::Dependency
112
104
  name: coveralls
113
105
  requirement: !ruby/object:Gem::Requirement
114
106
  requirements:
115
- - - ">="
107
+ - - "~>"
116
108
  - !ruby/object:Gem::Version
117
109
  version: '0'
118
110
  type: :development
119
111
  prerelease: false
120
112
  version_requirements: !ruby/object:Gem::Requirement
121
113
  requirements:
122
- - - ">="
114
+ - - "~>"
123
115
  - !ruby/object:Gem::Version
124
116
  version: '0'
125
117
  description: Client library to consume metrics from OpenTSDB
126
- email: phil@nine.ch
118
+ email:
119
+ - phil@nine.ch
127
120
  executables:
128
121
  - opentsdb-consumer
129
122
  extensions: []
130
- extra_rdoc_files:
131
- - LICENSE.txt
132
- - README.md
123
+ extra_rdoc_files: []
133
124
  files:
134
125
  - ".document"
126
+ - ".gitignore"
135
127
  - ".rspec"
136
128
  - ".travis.yml"
137
129
  - Gemfile
@@ -146,14 +138,16 @@ files:
146
138
  - lib/opentsdb-consumer/errors.rb
147
139
  - lib/opentsdb-consumer/metric.rb
148
140
  - lib/opentsdb-consumer/query.rb
141
+ - lib/opentsdb-consumer/rate.rb
149
142
  - lib/opentsdb-consumer/result.rb
150
143
  - opentsdb-consumer.gemspec
151
144
  - spec/opentsdb-consumer/client_spec.rb
152
145
  - spec/opentsdb-consumer/metric_spec.rb
153
146
  - spec/opentsdb-consumer/query_spec.rb
147
+ - spec/opentsdb-consumer/rate_spec.rb
154
148
  - spec/opentsdb-consumer/result_spec.rb
155
149
  - spec/spec_helper.rb
156
- homepage: http://github.com/ninech/opentsdb-consumer
150
+ homepage: http://github.com/ninech/
157
151
  licenses:
158
152
  - MIT
159
153
  metadata: {}
@@ -173,8 +167,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
167
  version: '0'
174
168
  requirements: []
175
169
  rubyforge_project:
176
- rubygems_version: 2.4.5.1
170
+ rubygems_version: 2.4.5
177
171
  signing_key:
178
172
  specification_version: 4
179
173
  summary: Client library to consume metrics from OpenTSDB
180
- test_files: []
174
+ test_files:
175
+ - spec/opentsdb-consumer/client_spec.rb
176
+ - spec/opentsdb-consumer/metric_spec.rb
177
+ - spec/opentsdb-consumer/query_spec.rb
178
+ - spec/opentsdb-consumer/rate_spec.rb
179
+ - spec/opentsdb-consumer/result_spec.rb
180
+ - spec/spec_helper.rb