pulse-meter-client-backport 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,7 @@ require 'pulse-meter/sensor/base'
2
2
  require 'pulse-meter/sensor/counter'
3
3
  require 'pulse-meter/sensor/hashed_counter'
4
4
  require 'pulse-meter/sensor/indicator'
5
+ require 'pulse-meter/sensor/uniq_counter'
5
6
  require 'pulse-meter/sensor/timeline'
6
7
  require 'pulse-meter/sensor/timelined/average'
7
8
  require 'pulse-meter/sensor/timelined/counter'
@@ -10,6 +11,7 @@ require 'pulse-meter/sensor/timelined/min'
10
11
  require 'pulse-meter/sensor/timelined/max'
11
12
  require 'pulse-meter/sensor/timelined/percentile'
12
13
  require 'pulse-meter/sensor/timelined/median'
14
+ require 'pulse-meter/sensor/timelined/uniq_counter'
13
15
 
14
16
  # Top level sensor module
15
17
  module PulseMeter
@@ -0,0 +1,16 @@
1
+ module PulseMeter
2
+ module Sensor
3
+ module Timelined
4
+ # Counts unique events per interval
5
+ class UniqCounter < Timeline
6
+ def aggregate_event(key, value)
7
+ redis.sadd(key, value)
8
+ end
9
+
10
+ def summarize(key)
11
+ redis.scard(key)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,22 @@
1
+ require 'json'
2
+
3
+ # Static counter to count unique values
4
+ module PulseMeter
5
+ module Sensor
6
+ class UniqCounter < Counter
7
+
8
+ # Processes event
9
+ # @param name [String] value to be counted
10
+ def event(name)
11
+ redis.sadd(value_key, name)
12
+ end
13
+
14
+ # Returs number of unique values ever sent to counter
15
+ # @return [Fixnum]
16
+ def value
17
+ redis.scard(value_key)
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,3 @@
1
1
  module PulseMeter
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe PulseMeter::Sensor::Timelined::UniqCounter do
4
+ it_should_behave_like "timeline sensor"
5
+ it_should_behave_like "timelined subclass", [:foo, :bar], 2
6
+ it_should_behave_like "timelined subclass", [:foo, :bar, :foo], 2
7
+ data = (1..100).map {rand(200)}
8
+ it_should_behave_like "timelined subclass", data, data.uniq.count
9
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe PulseMeter::Sensor::UniqCounter do
4
+ let(:name){ :some_counter }
5
+ let(:sensor){ described_class.new(name) }
6
+ let(:redis){ PulseMeter.redis }
7
+
8
+ describe "#event" do
9
+ it "should count unique values" do
10
+ expect{ sensor.event(:first) }.to change{sensor.value}.to(1)
11
+ expect{ sensor.event(:first) }.not_to change{sensor.value}
12
+ expect{ sensor.event(:second) }.to change{sensor.value}.from(1).to(2)
13
+ end
14
+ end
15
+
16
+ describe "#value" do
17
+ it "should have initial value 0" do
18
+ sensor.value.should == 0
19
+ end
20
+
21
+ it "should return count of unique values" do
22
+ data = (1..100).map {rand(200)}
23
+ data.each {|e| sensor.event(e)}
24
+ sensor.value.should == data.uniq.count
25
+ end
26
+ end
27
+
28
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pulse-meter-client-backport
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ilya Averyanov
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-06-08 00:00:00 Z
19
+ date: 2012-06-21 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  version_requirements: &id001 !ruby/object:Gem::Requirement
@@ -212,6 +212,8 @@ files:
212
212
  - lib/pulse-meter/sensor/timelined/median.rb
213
213
  - lib/pulse-meter/sensor/timelined/min.rb
214
214
  - lib/pulse-meter/sensor/timelined/percentile.rb
215
+ - lib/pulse-meter/sensor/timelined/uniq_counter.rb
216
+ - lib/pulse-meter/sensor/uniq_counter.rb
215
217
  - lib/pulse-meter/version.rb
216
218
  - pulse-meter-client-backport.gemspec
217
219
  - spec/pulse_meter/mixins/dumper_spec.rb
@@ -229,6 +231,8 @@ files:
229
231
  - spec/pulse_meter/sensor/timelined/median_spec.rb
230
232
  - spec/pulse_meter/sensor/timelined/min_spec.rb
231
233
  - spec/pulse_meter/sensor/timelined/percentile_spec.rb
234
+ - spec/pulse_meter/sensor/timelined/uniq_counter_spec.rb
235
+ - spec/pulse_meter/sensor/uniq_counter_spec.rb
232
236
  - spec/pulse_meter_spec.rb
233
237
  - spec/shared_examples/timeline_sensor.rb
234
238
  - spec/shared_examples/timelined_subclass.rb
@@ -285,6 +289,8 @@ test_files:
285
289
  - spec/pulse_meter/sensor/timelined/median_spec.rb
286
290
  - spec/pulse_meter/sensor/timelined/min_spec.rb
287
291
  - spec/pulse_meter/sensor/timelined/percentile_spec.rb
292
+ - spec/pulse_meter/sensor/timelined/uniq_counter_spec.rb
293
+ - spec/pulse_meter/sensor/uniq_counter_spec.rb
288
294
  - spec/pulse_meter_spec.rb
289
295
  - spec/shared_examples/timeline_sensor.rb
290
296
  - spec/shared_examples/timelined_subclass.rb