ruby-metrics 0.9.0 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,297 @@
1
+ require 'spec_helper'
2
+ require 'opentsdb/client'
3
+ require 'ruby-metrics/reporters/opentsdb'
4
+ require 'ruby-metrics'
5
+ require 'timecop'
6
+
7
+ module Metrics
8
+ module Reporters
9
+ describe 'OpenTSDBReporter' do
10
+
11
+ let(:mock_tsdb_client) {
12
+ mock_tsdb_client = double(OpenTSDB::Client)
13
+ }
14
+
15
+ let(:reporter) {
16
+ expect(OpenTSDB::Client).to receive(:new).and_return mock_tsdb_client
17
+ OpenTSDBReporter.new(:tags => {:foo => 'bar'})
18
+ }
19
+
20
+ let(:agent) {
21
+ Metrics::Agent.new
22
+ }
23
+
24
+ it 'should report a counter correctly' do
25
+ counter = agent.counter :my_counter
26
+ counter.incr
27
+ counter.incr
28
+
29
+ counter_data = {
30
+ :value => 2,
31
+ :timestamp => anything,
32
+ :tags => {
33
+ :units => '',
34
+ :foo => 'bar'
35
+ },
36
+ :metric => 'my_counter'
37
+ }
38
+ expect(mock_tsdb_client).to receive(:put).with(counter_data)
39
+
40
+ reporter.report(agent)
41
+ end
42
+
43
+ it 'should report a tagged counter correctly' do
44
+ counter = agent.counter :logins, 'logins'
45
+ counter.incr
46
+ counter.tag(:user, 'sam')
47
+
48
+ counter_data = {
49
+ :value => 1,
50
+ :timestamp => anything,
51
+ :tags => {
52
+ :units => 'logins',
53
+ :foo => 'bar',
54
+ :user => 'sam'
55
+ },
56
+ :metric => 'logins'
57
+ }
58
+ expect(mock_tsdb_client).to receive(:put).with(counter_data)
59
+
60
+ reporter.report(agent)
61
+ end
62
+
63
+ it 'should report a gauge that returns a hash' do
64
+ gauge = agent.gauge :my_gauge do
65
+ {
66
+ :hit_count => 42,
67
+ :http_requests => 320
68
+ }
69
+ end
70
+ gauge.tag(:mytag, 'somevalue')
71
+
72
+
73
+ tags = {
74
+ :units => '',
75
+ :foo => 'bar',
76
+ :mytag => 'somevalue'
77
+ }
78
+
79
+ gauge_hit_data = {
80
+ :value => 42,
81
+ :timestamp => anything,
82
+ :tags => tags,
83
+ :metric => 'my_gauge.hit_count'
84
+ }
85
+ gauge_requests_data = {
86
+ :value => 320,
87
+ :timestamp => anything,
88
+ :tags => tags,
89
+ :metric => 'my_gauge.http_requests'
90
+ }
91
+ expect(mock_tsdb_client).to receive(:put).with(gauge_hit_data)
92
+ expect(mock_tsdb_client).to receive(:put).with(gauge_requests_data)
93
+
94
+ reporter.report(agent)
95
+ end
96
+
97
+
98
+ it 'should report a gauge that returns a non-hash value' do
99
+ agent.gauge :boring_gauge, 'units' do
100
+ 42
101
+ end
102
+
103
+ gauge_data = {
104
+ :value => 42,
105
+ :timestamp => anything,
106
+ :tags => {
107
+ :units => 'units',
108
+ :foo => 'bar',
109
+ },
110
+ :metric => 'boring_gauge'
111
+ }
112
+ expect(mock_tsdb_client).to receive(:put).with(gauge_data)
113
+
114
+ reporter.report(agent)
115
+ end
116
+
117
+ it 'should report a timer' do
118
+ timer = agent.timer :some_timer, 'requests'
119
+ timer.update(5, :seconds)
120
+
121
+ timer_counter_data = {
122
+ :value => 1,
123
+ :timestamp => anything,
124
+ :tags => {
125
+ :units => 'requests',
126
+ :foo => 'bar'
127
+ },
128
+ :metric => 'some_timer.count'
129
+ }
130
+ expect(mock_tsdb_client).to receive(:put).with(timer_counter_data)
131
+
132
+ timer_fifteen = {
133
+ :value => anything,
134
+ :timestamp => anything,
135
+ :tags => {
136
+ :units => 'requests/sec',
137
+ :foo => 'bar'
138
+ },
139
+ :metric => 'some_timer.fifteen_minute_rate'
140
+ }
141
+ expect(mock_tsdb_client).to receive(:put).with(timer_fifteen)
142
+
143
+ timer_five = {
144
+ :value => anything,
145
+ :timestamp => anything,
146
+ :tags => {
147
+ :units => 'requests/sec',
148
+ :foo => 'bar'
149
+ },
150
+ :metric => 'some_timer.five_minute_rate'
151
+ }
152
+ expect(mock_tsdb_client).to receive(:put).with(timer_five)
153
+
154
+
155
+ timer_one = {
156
+ :value => anything,
157
+ :timestamp => anything,
158
+ :tags => {
159
+ :units => 'requests/sec',
160
+ :foo => 'bar'
161
+ },
162
+ :metric => 'some_timer.one_minute_rate'
163
+ }
164
+ expect(mock_tsdb_client).to receive(:put).with(timer_one)
165
+
166
+
167
+ timer_min = {
168
+ :value => 5.0,
169
+ :timestamp => anything,
170
+ :tags => {
171
+ :units => 'sec/requests',
172
+ :foo => 'bar'
173
+ },
174
+ :metric => 'some_timer.min'
175
+ }
176
+ expect(mock_tsdb_client).to receive(:put).with(timer_min)
177
+
178
+
179
+ timer_max = {
180
+ :value => 5.0,
181
+ :timestamp => anything,
182
+ :tags => {
183
+ :units => 'sec/requests',
184
+ :foo => 'bar'
185
+ },
186
+ :metric => 'some_timer.max'
187
+ }
188
+ expect(mock_tsdb_client).to receive(:put).with(timer_max)
189
+
190
+ timer_mean = {
191
+ :value => 5.0,
192
+ :timestamp => anything,
193
+ :tags => {
194
+ :units => 'sec/requests',
195
+ :foo => 'bar'
196
+ },
197
+ :metric => 'some_timer.mean'
198
+ }
199
+ expect(mock_tsdb_client).to receive(:put).with(timer_mean)
200
+
201
+ reporter.report(agent)
202
+ end
203
+
204
+ it 'should report a gauge that returns a non-hash value' do
205
+ agent.gauge :boring_gauge, 'units' do
206
+ 42
207
+ end
208
+
209
+ gauge_data = {
210
+ :value => 42,
211
+ :timestamp => anything,
212
+ :tags => {
213
+ :units => 'units',
214
+ :foo => 'bar',
215
+ },
216
+ :metric => 'boring_gauge'
217
+ }
218
+ expect(mock_tsdb_client).to receive(:put).with(gauge_data)
219
+
220
+ reporter.report(agent)
221
+ end
222
+
223
+ it 'should report a meter' do
224
+ meter = agent.meter :http_requests, 'requests'
225
+ meter.mark
226
+ meter.mark
227
+ meter.mark
228
+ meter.tick
229
+ meter.mark
230
+ meter.tag :somekey, 'value'
231
+
232
+ meter_counter_data = {
233
+ :value => anything,
234
+ :timestamp => anything,
235
+ :tags => {
236
+ :units => 'requests',
237
+ :foo => 'bar',
238
+ :somekey => 'value'
239
+ },
240
+ :metric => 'http_requests.count'
241
+ }
242
+ expect(mock_tsdb_client).to receive(:put).with(meter_counter_data)
243
+
244
+ meter_fifteen = {
245
+ :value => anything,
246
+ :timestamp => anything,
247
+ :tags => {
248
+ :units => 'requests/sec',
249
+ :foo => 'bar',
250
+ :somekey => 'value'
251
+ },
252
+ :metric => 'http_requests.fifteen_minute_rate'
253
+ }
254
+ expect(mock_tsdb_client).to receive(:put).with(meter_fifteen)
255
+
256
+ meter_five = {
257
+ :value => anything,
258
+ :timestamp => anything,
259
+ :tags => {
260
+ :units => 'requests/sec',
261
+ :foo => 'bar',
262
+ :somekey => 'value'
263
+ },
264
+ :metric => 'http_requests.five_minute_rate'
265
+ }
266
+ expect(mock_tsdb_client).to receive(:put).with(meter_five)
267
+
268
+
269
+ meter_one = {
270
+ :value => anything,
271
+ :timestamp => anything,
272
+ :tags => {
273
+ :units => 'requests/sec',
274
+ :foo => 'bar',
275
+ :somekey => 'value'
276
+ },
277
+ :metric => 'http_requests.one_minute_rate'
278
+ }
279
+ expect(mock_tsdb_client).to receive(:put).with(meter_one)
280
+
281
+ meter_mean = {
282
+ :value => anything,
283
+ :timestamp => anything,
284
+ :tags => {
285
+ :units => 'requests/sec',
286
+ :foo => 'bar',
287
+ :somekey => 'value'
288
+ },
289
+ :metric => 'http_requests.mean_rate'
290
+ }
291
+ expect(mock_tsdb_client).to receive(:put).with(meter_mean)
292
+
293
+ reporter.report(agent)
294
+ end
295
+ end
296
+ end
297
+ end
metadata CHANGED
@@ -1,102 +1,93 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
5
- prerelease:
4
+ version: 0.9.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - John Ewart
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-05-08 00:00:00.000000000 Z
11
+ date: 2021-11-04 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: json
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: '1.5'
22
- - - ! '>='
19
+ version: '2.3'
20
+ - - ">="
23
21
  - !ruby/object:Gem::Version
24
- version: 1.5.5
22
+ version: 2.3.0
25
23
  type: :runtime
26
24
  prerelease: false
27
25
  version_requirements: !ruby/object:Gem::Requirement
28
- none: false
29
26
  requirements:
30
- - - ~>
27
+ - - "~>"
31
28
  - !ruby/object:Gem::Version
32
- version: '1.5'
33
- - - ! '>='
29
+ version: '2.3'
30
+ - - ">="
34
31
  - !ruby/object:Gem::Version
35
- version: 1.5.5
32
+ version: 2.3.0
36
33
  - !ruby/object:Gem::Dependency
37
34
  name: rspec
38
35
  requirement: !ruby/object:Gem::Requirement
39
- none: false
40
36
  requirements:
41
- - - ~>
37
+ - - "~>"
42
38
  - !ruby/object:Gem::Version
43
39
  version: '2.14'
44
- - - ! '>='
40
+ - - ">="
45
41
  - !ruby/object:Gem::Version
46
42
  version: 2.14.0
47
43
  type: :development
48
44
  prerelease: false
49
45
  version_requirements: !ruby/object:Gem::Requirement
50
- none: false
51
46
  requirements:
52
- - - ~>
47
+ - - "~>"
53
48
  - !ruby/object:Gem::Version
54
49
  version: '2.14'
55
- - - ! '>='
50
+ - - ">="
56
51
  - !ruby/object:Gem::Version
57
52
  version: 2.14.0
58
53
  - !ruby/object:Gem::Dependency
59
54
  name: simplecov
60
55
  requirement: !ruby/object:Gem::Requirement
61
- none: false
62
56
  requirements:
63
- - - ~>
57
+ - - "~>"
64
58
  - !ruby/object:Gem::Version
65
59
  version: '0.3'
66
- - - ! '>='
60
+ - - ">="
67
61
  - !ruby/object:Gem::Version
68
62
  version: 0.3.8
69
63
  type: :development
70
64
  prerelease: false
71
65
  version_requirements: !ruby/object:Gem::Requirement
72
- none: false
73
66
  requirements:
74
- - - ~>
67
+ - - "~>"
75
68
  - !ruby/object:Gem::Version
76
69
  version: '0.3'
77
- - - ! '>='
70
+ - - ">="
78
71
  - !ruby/object:Gem::Version
79
72
  version: 0.3.8
80
73
  - !ruby/object:Gem::Dependency
81
74
  name: rack-test
82
75
  requirement: !ruby/object:Gem::Requirement
83
- none: false
84
76
  requirements:
85
- - - ~>
77
+ - - "~>"
86
78
  - !ruby/object:Gem::Version
87
79
  version: '0.5'
88
- - - ! '>='
80
+ - - ">="
89
81
  - !ruby/object:Gem::Version
90
82
  version: 0.5.7
91
83
  type: :development
92
84
  prerelease: false
93
85
  version_requirements: !ruby/object:Gem::Requirement
94
- none: false
95
86
  requirements:
96
- - - ~>
87
+ - - "~>"
97
88
  - !ruby/object:Gem::Version
98
89
  version: '0.5'
99
- - - ! '>='
90
+ - - ">="
100
91
  - !ruby/object:Gem::Version
101
92
  version: 0.5.7
102
93
  description: A Ruby implementation of metrics inspired by @coda's JVM metrics for
@@ -107,10 +98,10 @@ executables: []
107
98
  extensions: []
108
99
  extra_rdoc_files: []
109
100
  files:
110
- - .bundle/config
111
- - .gitignore
112
- - .rvmrc
113
- - .travis.yml
101
+ - ".bundle/config"
102
+ - ".gitignore"
103
+ - ".rvmrc"
104
+ - ".travis.yml"
114
105
  - CHANGELOG.md
115
106
  - Gemfile
116
107
  - LICENSE
@@ -132,6 +123,7 @@ files:
132
123
  - lib/ruby-metrics/instruments/counter.rb
133
124
  - lib/ruby-metrics/instruments/gauge.rb
134
125
  - lib/ruby-metrics/instruments/histogram.rb
126
+ - lib/ruby-metrics/instruments/instrument.rb
135
127
  - lib/ruby-metrics/instruments/meter.rb
136
128
  - lib/ruby-metrics/instruments/timer.rb
137
129
  - lib/ruby-metrics/integration.rb
@@ -140,12 +132,12 @@ files:
140
132
  - lib/ruby-metrics/integration/webrick.rb
141
133
  - lib/ruby-metrics/logging.rb
142
134
  - lib/ruby-metrics/reporter.rb
135
+ - lib/ruby-metrics/reporters/ganglia.rb
136
+ - lib/ruby-metrics/reporters/librato.rb
143
137
  - lib/ruby-metrics/statistics/exponential_sample.rb
144
138
  - lib/ruby-metrics/statistics/uniform_sample.rb
145
139
  - lib/ruby-metrics/time_units.rb
146
140
  - lib/ruby-metrics/version.rb
147
- - ruby-metrics-ganglia.gemspec
148
- - ruby-metrics-librato.gemspec
149
141
  - ruby-metrics-opentsdb.gemspec
150
142
  - ruby-metrics.gemspec
151
143
  - spec/agent_spec.rb
@@ -156,33 +148,45 @@ files:
156
148
  - spec/instruments/timer_spec.rb
157
149
  - spec/integration/rack_endpoint_spec.rb
158
150
  - spec/integration/rack_middleware_spec.rb
151
+ - spec/reporter_spec.rb
152
+ - spec/reporters/opentsdb_spec.rb
159
153
  - spec/spec_helper.rb
160
154
  - spec/statistics/exponential_sample_spec.rb
161
155
  - spec/statistics/uniform_sample_spec.rb
162
- - spec/time_units_spec.rb
163
156
  homepage: https://github.com/johnewart/ruby-metrics
164
157
  licenses:
165
158
  - MIT
166
- post_install_message:
159
+ metadata: {}
160
+ post_install_message:
167
161
  rdoc_options: []
168
162
  require_paths:
169
163
  - lib
170
164
  required_ruby_version: !ruby/object:Gem::Requirement
171
- none: false
172
165
  requirements:
173
- - - ! '>='
166
+ - - ">="
174
167
  - !ruby/object:Gem::Version
175
168
  version: '0'
176
169
  required_rubygems_version: !ruby/object:Gem::Requirement
177
- none: false
178
170
  requirements:
179
- - - ! '>='
171
+ - - ">="
180
172
  - !ruby/object:Gem::Version
181
173
  version: '0'
182
174
  requirements: []
183
- rubyforge_project:
184
- rubygems_version: 1.8.23.2
185
- signing_key:
186
- specification_version: 3
175
+ rubygems_version: 3.1.2
176
+ signing_key:
177
+ specification_version: 4
187
178
  summary: Metrics for Ruby
188
- test_files: []
179
+ test_files:
180
+ - spec/agent_spec.rb
181
+ - spec/instruments/counter_spec.rb
182
+ - spec/instruments/gauge_spec.rb
183
+ - spec/instruments/histogram_spec.rb
184
+ - spec/instruments/meter_spec.rb
185
+ - spec/instruments/timer_spec.rb
186
+ - spec/integration/rack_endpoint_spec.rb
187
+ - spec/integration/rack_middleware_spec.rb
188
+ - spec/reporter_spec.rb
189
+ - spec/reporters/opentsdb_spec.rb
190
+ - spec/spec_helper.rb
191
+ - spec/statistics/exponential_sample_spec.rb
192
+ - spec/statistics/uniform_sample_spec.rb
@@ -1,21 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path('../lib', __FILE__)
3
- require 'ruby-metrics/version'
4
-
5
- Gem::Specification.new do |s|
6
- s.name = 'ruby-metrics-ganglia'
7
- s.version = Metrics::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ['John Ewart']
10
- s.email = ['john@johnewart.net']
11
- s.homepage = 'https://github.com/johnewart/ruby-metrics'
12
- s.summary = %q{Ganglia reporter for ruby-metrics}
13
- s.description = %q{A reporter that uses Ganglia's to stash metric data}
14
- s.license = 'MIT'
15
-
16
- s.files = ['lib/ruby-metrics/reporters/ganglia.rb']
17
- s.require_paths = ['lib']
18
-
19
- s.add_dependency 'gmetric', '0.1.3'
20
- s.add_dependency 'ruby-metrics', Metrics::VERSION
21
- end
@@ -1,20 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path('../lib', __FILE__)
3
- require 'ruby-metrics/version'
4
-
5
- Gem::Specification.new do |s|
6
- s.name = 'ruby-metrics-librato'
7
- s.version = Metrics::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ['John Ewart']
10
- s.email = ['john@johnewart.net']
11
- s.homepage = 'https://github.com/johnewart/ruby-metrics'
12
- s.summary = %q{Librato reporter for ruby-metrics}
13
- s.description = %q{A reporter that uses Librato to stash metric data}
14
- s.license = 'MIT'
15
-
16
- s.files = ['lib/ruby-metrics/reporters/librato.rb']
17
- s.require_paths = ['lib']
18
-
19
- s.add_dependency 'ruby-metrics', Metrics::VERSION
20
- end
@@ -1,13 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Metrics::TimeUnit do
4
- it "should raise NotImplementedError for #to_nsec" do
5
- begin
6
- Metrics::TimeUnit.to_nsec
7
- rescue NotImplementedError
8
- true
9
- else
10
- fail
11
- end
12
- end
13
- end