counters 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/counters/base.rb +3 -3
- data/lib/counters/file.rb +2 -2
- data/lib/counters/memory.rb +2 -2
- data/lib/counters/redis.rb +2 -2
- data/lib/counters/stats_d.rb +2 -2
- data/lib/counters/version.rb +1 -1
- data/spec/spec_helper.rb +4 -0
- data/spec/statsd_counter_spec.rb +6 -0
- metadata +2 -2
data/lib/counters/base.rb
CHANGED
@@ -10,9 +10,9 @@ module Counters
|
|
10
10
|
@namespace = options[:namespace]
|
11
11
|
end
|
12
12
|
|
13
|
-
def hit(key)
|
13
|
+
def hit(key, value=1)
|
14
14
|
validate(key)
|
15
|
-
record_hit(namespaced_key(key))
|
15
|
+
record_hit(namespaced_key(key), value)
|
16
16
|
end
|
17
17
|
|
18
18
|
def magnitude(key, value)
|
@@ -47,7 +47,7 @@ module Counters
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
def record_hit(key)
|
50
|
+
def record_hit(key, value)
|
51
51
|
raise "Subclass Responsibility Error: must be implemented in instances of #{self.class} but isn't"
|
52
52
|
end
|
53
53
|
protected :record_hit
|
data/lib/counters/file.rb
CHANGED
data/lib/counters/memory.rb
CHANGED
data/lib/counters/redis.rb
CHANGED
@@ -10,8 +10,8 @@ module Counters
|
|
10
10
|
@base_key = options.fetch(:base_key) { raise "Missing :base_key from #{options.inspect}" }
|
11
11
|
end
|
12
12
|
|
13
|
-
def record_hit(key)
|
14
|
-
@redis.hincrby(@base_key, "hits.#{key}",
|
13
|
+
def record_hit(key, increment)
|
14
|
+
@redis.hincrby(@base_key, "hits.#{key}", increment)
|
15
15
|
end
|
16
16
|
|
17
17
|
def record_magnitude(key, amount)
|
data/lib/counters/stats_d.rb
CHANGED
@@ -27,8 +27,8 @@ module Counters
|
|
27
27
|
socket.send("pings.#{key}:1|c", 0, host, port)
|
28
28
|
end
|
29
29
|
|
30
|
-
def record_hit(key)
|
31
|
-
socket.send("hits.#{key}
|
30
|
+
def record_hit(key, increment)
|
31
|
+
socket.send("hits.#{key}:#{increment}|c", 0, host, port)
|
32
32
|
end
|
33
33
|
|
34
34
|
# StatsD expects millisecond resolution
|
data/lib/counters/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -38,6 +38,10 @@ shared_examples_for "all counters" do
|
|
38
38
|
value.should == "the returned value"
|
39
39
|
end
|
40
40
|
|
41
|
+
it "should allow hitting with a specific value increment" do
|
42
|
+
lambda { counter.hit "tada", 17 }.should_not raise_error
|
43
|
+
end
|
44
|
+
|
41
45
|
it "should return a sub-namespaced counter on-demand" do
|
42
46
|
other = counter.namespace("sub")
|
43
47
|
other.namespace.should == "#{counter.namespace}.sub"
|
data/spec/statsd_counter_spec.rb
CHANGED
@@ -90,5 +90,11 @@ describe Counters::StatsD do
|
|
90
90
|
socket.should_receive(:send).with(/^pings\.beer\.tulip\b/, anything, anything, anything)
|
91
91
|
counter.ping "tulip"
|
92
92
|
end
|
93
|
+
|
94
|
+
it "should increment with the #hit value" do
|
95
|
+
counter.namespace = "pow"
|
96
|
+
socket.should_receive(:send).with(/^hits\.pow\.loudness:17\b/, anything, anything, anything)
|
97
|
+
counter.hit "loudness", 17
|
98
|
+
end
|
93
99
|
end
|
94
100
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: counters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.
|
5
|
+
version: 1.3.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- "Fran\xC3\xA7ois Beausoleil"
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-06-01 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|