statsy 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/statsy.rb +14 -11
- data/test/statsy_test.rb +5 -0
- metadata +3 -3
data/lib/statsy.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Client to access statsd service authored by etsy. Yay etsy!
|
2
2
|
# https://github.com/etsy/statsd
|
3
3
|
module Statsy
|
4
|
-
VERSION="0.1.
|
4
|
+
VERSION="0.1.2"
|
5
5
|
|
6
6
|
module Transport
|
7
7
|
require 'socket'
|
@@ -57,13 +57,7 @@ module Statsy
|
|
57
57
|
# client.increment("coffee.single-espresso", 1, 0.5) # 50% of the time
|
58
58
|
#
|
59
59
|
def increment(stat, count=1, sampling=1)
|
60
|
-
|
61
|
-
if Kernel.rand < sampling
|
62
|
-
@transport.write("%s:%d|c@%f" % [ stat, count, sampling ])
|
63
|
-
end
|
64
|
-
else
|
65
|
-
@transport.write("%s:%d|c" % [ stat, count ])
|
66
|
-
end
|
60
|
+
write(stat, count, 'c', sampling)
|
67
61
|
self
|
68
62
|
end
|
69
63
|
|
@@ -73,9 +67,7 @@ module Statsy
|
|
73
67
|
# client.measure("foo.backendtime", response.headers["X-Runtime"].to_i)
|
74
68
|
#
|
75
69
|
def measure(stat, time, sampling=1)
|
76
|
-
|
77
|
-
@transport.write("%s:%d|ms" % [ stat, time ])
|
78
|
-
end
|
70
|
+
write(stat, time, 'ms', sampling)
|
79
71
|
self
|
80
72
|
end
|
81
73
|
|
@@ -109,5 +101,16 @@ module Statsy
|
|
109
101
|
end
|
110
102
|
self
|
111
103
|
end
|
104
|
+
|
105
|
+
private
|
106
|
+
def write(stat, value, modifier, sampling)
|
107
|
+
if sampling < 1
|
108
|
+
if Kernel.rand < sampling
|
109
|
+
@transport.write("%s:%d|%s@%f" % [ stat, value, modifier, sampling ])
|
110
|
+
end
|
111
|
+
else
|
112
|
+
@transport.write("%s:%d|%s" % [ stat, value, modifier ])
|
113
|
+
end
|
114
|
+
end
|
112
115
|
end
|
113
116
|
end
|
data/test/statsy_test.rb
CHANGED
@@ -40,6 +40,11 @@ class Unit < Test::Unit::TestCase
|
|
40
40
|
assert_equal nil, @transport.shift
|
41
41
|
end
|
42
42
|
|
43
|
+
def test_measure_should_include_sample_rate
|
44
|
+
@client.measure("foo.sampled.timing", 100, 0.999999)
|
45
|
+
assert_equal "foo.sampled.timing:100|ms@0.999999", @transport.shift
|
46
|
+
end
|
47
|
+
|
43
48
|
def test_increment_twice_should_write_twice
|
44
49
|
@client.increment("foo.inc", 1)
|
45
50
|
@client.increment("foo.inc", 2)
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 2
|
9
|
+
version: 0.1.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Sean Treadway
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-09-
|
17
|
+
date: 2011-09-27 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|