statsd-ruby 0.3.0 → 1.0.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/.gitignore ADDED
@@ -0,0 +1,43 @@
1
+ # simplecov generated
2
+ coverage
3
+
4
+ # rdoc generated
5
+ rdoc
6
+
7
+ # yard generated
8
+ doc
9
+ .yardoc
10
+
11
+ # bundler
12
+ .bundle
13
+ Gemfile.lock
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
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ rvm:
4
+ - 1.8.7
5
+ - 1.9.3
6
+ - jruby-19mode
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/README.rdoc CHANGED
@@ -1,6 +1,11 @@
1
- = statsd
1
+ = statsd-ruby {<img src="https://secure.travis-ci.org/reinh/statsd-ruby.png" />}[http://travis-ci.org/reinh/statsd-ruby]
2
2
 
3
- A Ruby statsd client (https://github.com/etsy/statsd)
3
+ A Ruby client for {StatsD}[https://github.com/etsy/statsd]
4
+
5
+ = Installing
6
+
7
+ Bundler:
8
+ gem "statsd-ruby", :require => "statsd"
4
9
 
5
10
  = Testing
6
11
 
@@ -8,6 +13,10 @@ Run the specs with <tt>rake spec</tt>
8
13
 
9
14
  Run the specs and include live integration specs with <tt>LIVE=true rake spec</tt>. Note: This will test over a real UDP socket.
10
15
 
16
+ = Performance
17
+
18
+ * A short note about DNS: If you use a dns name for the host option, then you will want to use a local caching dns service for optimial performance (e.g. nscd).
19
+
11
20
  == Contributing to statsd
12
21
 
13
22
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
@@ -22,8 +31,14 @@ Run the specs and include live integration specs with <tt>LIVE=true rake spec</t
22
31
 
23
32
  * Rein Henrichs
24
33
  * Ray Krueger
34
+ * Jeremy Kemper
35
+ * Ryan Tomayko
36
+ * Gabriel Burt
37
+ * Rick Olson
38
+ * Trae Robrock
39
+ * Corey Donohoe
40
+ * James Tucker
25
41
 
26
42
  == Copyright
27
43
 
28
- Copyright (c) 2011 Rein Henrichs. See LICENSE.txt for
29
- further details.
44
+ Copyright (c) 2011 Rein Henrichs. See LICENSE.txt for further details.
data/Rakefile CHANGED
@@ -1,39 +1,15 @@
1
- require 'rubygems'
2
- require 'rake'
1
+ require 'bundler/setup'
2
+ require 'bundler/gem_tasks'
3
3
 
4
- require 'jeweler'
5
- Jeweler::Tasks.new do |gem|
6
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
7
- gem.name = "statsd-ruby"
8
- gem.homepage = "http://github.com/reinh/statsd"
9
- gem.license = "MIT"
10
- gem.summary = %Q{A Statsd client in Ruby}
11
- gem.description = %Q{A Statsd client in Ruby}
12
- gem.email = "rein@phpfog.com"
13
- gem.authors = ["Rein Henrichs"]
14
- gem.add_development_dependency "minitest", ">= 0"
15
- gem.add_development_dependency "yard", "~> 0.6.0"
16
- gem.add_development_dependency "jeweler", "~> 1.5.2"
17
- gem.add_development_dependency "rcov", ">= 0"
18
- end
19
- Jeweler::RubygemsDotOrgTasks.new
4
+ task :default => :spec
20
5
 
21
6
  require 'rake/testtask'
22
7
  Rake::TestTask.new(:spec) do |spec|
23
8
  spec.libs << 'lib' << 'spec'
24
9
  spec.pattern = 'spec/**/*_spec.rb'
25
10
  spec.verbose = true
11
+ spec.warning = true
26
12
  end
27
13
 
28
- require 'rcov/rcovtask'
29
- Rcov::RcovTask.new do |spec|
30
- spec.libs << 'lib' << 'spec'
31
- spec.pattern = 'spec/**/*_spec.rb'
32
- spec.verbose = true
33
- spec.rcov_opts << "--exclude spec,gems"
34
- end
35
-
36
- task :default => :spec
37
-
38
14
  require 'yard'
39
15
  YARD::Rake::YardocTask.new
data/lib/statsd.rb CHANGED
@@ -7,65 +7,118 @@ require 'socket'
7
7
  # @example Send some stats
8
8
  # $statsd.increment 'garets'
9
9
  # $statsd.timing 'glork', 320
10
+ # $statsd.gauge 'bork', 100
10
11
  # @example Use {#time} to time the execution of a block
11
12
  # $statsd.time('account.activate') { @account.activate! }
12
13
  # @example Create a namespaced statsd client and increment 'account.activate'
13
14
  # statsd = Statsd.new('localhost').tap{|sd| sd.namespace = 'account'}
14
15
  # statsd.increment 'activate'
16
+ #
17
+ # Statsd instances are thread safe for general usage, by using a thread local
18
+ # UDPSocket and carrying no state. The attributes are stateful, and are not
19
+ # mutexed, it is expected that users will not change these at runtime in
20
+ # threaded environments. If users require such use cases, it is recommend that
21
+ # users either mutex around their Statsd object, or create separate objects for
22
+ # each namespace / host+port combination.
15
23
  class Statsd
16
24
  # A namespace to prepend to all statsd calls.
17
- attr_accessor :namespace
25
+ attr_reader :namespace
26
+
27
+ # StatsD host. Defaults to 127.0.0.1.
28
+ attr_reader :host
29
+
30
+ # StatsD port. Defaults to 8125.
31
+ attr_reader :port
18
32
 
19
- #characters that will be replaced with _ in stat names
20
- RESERVED_CHARS_REGEX = /[\:\|\@]/
21
-
22
33
  class << self
23
- # Set to any standard logger instance (including stdlib's Logger) to enable
24
- # stat logging using logger.debug
34
+ # Set to a standard logger instance to enable debug logging.
25
35
  attr_accessor :logger
26
36
  end
27
-
37
+
28
38
  # @param [String] host your statsd host
29
39
  # @param [Integer] port your statsd port
30
- def initialize(host, port=8125)
31
- @host, @port = host, port
40
+ def initialize(host = '127.0.0.1', port = 8125)
41
+ self.host, self.port = host, port
42
+ @prefix = nil
32
43
  end
33
44
 
34
- # Sends an increment (count = 1) for the given stat to the statsd server.
45
+ # @attribute [w] namespace
46
+ # Writes are not thread safe.
47
+ def namespace=(namespace)
48
+ @namespace = namespace
49
+ @prefix = "#{namespace}."
50
+ end
51
+
52
+ # @attribute [w] host
53
+ # Writes are not thread safe.
54
+ def host=(host)
55
+ @host = host || '127.0.0.1'
56
+ end
57
+
58
+ # @attribute [w] port
59
+ # Writes are not thread safe.
60
+ def port=(port)
61
+ @port = port || 8125
62
+ end
63
+
64
+ # Sends an increment (count = 1) for the given stat to the statsd server.
35
65
  #
36
- # @param stat (see #count)
37
- # @param sample_rate (see #count)
66
+ # @param [String] stat stat name
67
+ # @param [Numeric] sample_rate sample rate, 1 for always
38
68
  # @see #count
39
- def increment(stat, sample_rate=1); count stat, 1, sample_rate end
69
+ def increment(stat, sample_rate=1)
70
+ count stat, 1, sample_rate
71
+ end
40
72
 
41
- # Sends a decrement (count = -1) for the given stat to the statsd server.
73
+ # Sends a decrement (count = -1) for the given stat to the statsd server.
42
74
  #
43
- # @param stat (see #count)
44
- # @param sample_rate (see #count)
75
+ # @param [String] stat stat name
76
+ # @param [Numeric] sample_rate sample rate, 1 for always
45
77
  # @see #count
46
- def decrement(stat, sample_rate=1); count stat, -1, sample_rate end
78
+ def decrement(stat, sample_rate=1)
79
+ count stat, -1, sample_rate
80
+ end
47
81
 
48
82
  # Sends an arbitrary count for the given stat to the statsd server.
49
83
  #
50
84
  # @param [String] stat stat name
51
85
  # @param [Integer] count count
52
- # @param [Integer] sample_rate sample rate, 1 for always
53
- def count(stat, count, sample_rate=1); send stat, count, 'c', sample_rate end
86
+ # @param [Numeric] sample_rate sample rate, 1 for always
87
+ def count(stat, count, sample_rate=1)
88
+ send_stats stat, count, :c, sample_rate
89
+ end
90
+
91
+ # Sends an arbitary gauge value for the given stat to the statsd server.
92
+ #
93
+ # This is useful for recording things like available disk space,
94
+ # memory usage, and the like, which have different semantics than
95
+ # counters.
96
+ #
97
+ # @param [String] stat stat name.
98
+ # @param [Numeric] gauge value.
99
+ # @param [Numeric] sample_rate sample rate, 1 for always
100
+ # @example Report the current user count:
101
+ # $statsd.gauge('user.count', User.count)
102
+ def gauge(stat, value, sample_rate=1)
103
+ send_stats stat, value, :g, sample_rate
104
+ end
54
105
 
55
106
  # Sends a timing (in ms) for the given stat to the statsd server. The
56
107
  # sample_rate determines what percentage of the time this report is sent. The
57
108
  # statsd server then uses the sample_rate to correctly track the average
58
109
  # timing for the stat.
59
110
  #
60
- # @param stat stat name
111
+ # @param [String] stat stat name
61
112
  # @param [Integer] ms timing in milliseconds
62
- # @param [Integer] sample_rate sample rate, 1 for always
63
- def timing(stat, ms, sample_rate=1); send stat, ms, 'ms', sample_rate end
113
+ # @param [Numeric] sample_rate sample rate, 1 for always
114
+ def timing(stat, ms, sample_rate=1)
115
+ send_stats stat, ms, :ms, sample_rate
116
+ end
64
117
 
65
118
  # Reports execution time of the provided block using {#timing}.
66
119
  #
67
- # @param stat (see #timing)
68
- # @param sample_rate (see #timing)
120
+ # @param [String] stat stat name
121
+ # @param [Numeric] sample_rate sample rate, 1 for always
69
122
  # @yield The operation to be timed
70
123
  # @see #timing
71
124
  # @example Report the time (in ms) taken to activate an account
@@ -79,20 +132,24 @@ class Statsd
79
132
 
80
133
  private
81
134
 
82
- def sampled(sample_rate)
83
- yield unless sample_rate < 1 and rand > sample_rate
84
- end
85
-
86
- def send(stat, delta, type, sample_rate)
87
- prefix = "#{@namespace}." unless @namespace.nil?
88
- stat = stat.to_s.gsub('::', '.').gsub(RESERVED_CHARS_REGEX, '_')
89
- sampled(sample_rate) { send_to_socket("#{prefix}#{stat}:#{delta}|#{type}#{'|@' << sample_rate.to_s if sample_rate < 1}") }
135
+ def send_stats(stat, delta, type, sample_rate=1)
136
+ if sample_rate == 1 or rand < sample_rate
137
+ # Replace Ruby module scoping with '.' and reserved chars (: | @) with underscores.
138
+ stat = stat.to_s.gsub('::', '.').tr(':|@', '_')
139
+ rate = "|@#{sample_rate}" unless sample_rate == 1
140
+ send_to_socket "#{@prefix}#{stat}:#{delta}|#{type}#{rate}"
141
+ end
90
142
  end
91
143
 
92
144
  def send_to_socket(message)
93
- self.class.logger.debug {"Statsd: #{message}"} if self.class.logger
145
+ self.class.logger.debug { "Statsd: #{message}" } if self.class.logger
94
146
  socket.send(message, 0, @host, @port)
147
+ rescue => boom
148
+ self.class.logger.error { "Statsd: #{boom.class} #{boom}" } if self.class.logger
149
+ nil
95
150
  end
96
151
 
97
- def socket; @socket ||= UDPSocket.new end
152
+ def socket
153
+ Thread.current[:statsd_socket] ||= UDPSocket.new
154
+ end
98
155
  end
data/spec/helper.rb CHANGED
@@ -1,8 +1,9 @@
1
- require 'rubygems'
1
+ require 'bundler/setup'
2
2
  require 'minitest/autorun'
3
3
 
4
- $LOAD_PATH.unshift(File.dirname(__FILE__))
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ require 'simplecov'
5
+ SimpleCov.start
6
+
6
7
  require 'statsd'
7
8
  require 'logger'
8
9
 
data/spec/statsd_spec.rb CHANGED
@@ -1,16 +1,16 @@
1
1
  require 'helper'
2
2
 
3
3
  describe Statsd do
4
+ class Statsd
5
+ public :socket
6
+ end
7
+
4
8
  before do
5
9
  @statsd = Statsd.new('localhost', 1234)
6
- class << @statsd
7
- public :sampled # we need to test this
8
- attr_reader :host, :port # we also need to test this
9
- def socket; @socket ||= FakeUDPSocket.new end
10
- end
10
+ @socket = Thread.current[:statsd_socket] = FakeUDPSocket.new
11
11
  end
12
12
 
13
- after { @statsd.socket.clear }
13
+ after { Thread.current[:statsd_socket] = nil }
14
14
 
15
15
  describe "#initialize" do
16
16
  it "should set the host and port" do
@@ -18,22 +18,48 @@ describe Statsd do
18
18
  @statsd.port.must_equal 1234
19
19
  end
20
20
 
21
- it "should default the port to 8125" do
22
- Statsd.new('localhost').instance_variable_get('@port').must_equal 8125
21
+ it "should default the host to 127.0.0.1 and port to 8125" do
22
+ statsd = Statsd.new
23
+ statsd.host.must_equal '127.0.0.1'
24
+ statsd.port.must_equal 8125
25
+ end
26
+ end
27
+
28
+ describe "#host and #port" do
29
+ it "should set host and port" do
30
+ @statsd.host = '1.2.3.4'
31
+ @statsd.port = 5678
32
+ @statsd.host.must_equal '1.2.3.4'
33
+ @statsd.port.must_equal 5678
34
+ end
35
+
36
+ it "should not resolve hostnames to IPs" do
37
+ @statsd.host = 'localhost'
38
+ @statsd.host.must_equal 'localhost'
39
+ end
40
+
41
+ it "should set nil host to default" do
42
+ @statsd.host = nil
43
+ @statsd.host.must_equal '127.0.0.1'
44
+ end
45
+
46
+ it "should set nil port to default" do
47
+ @statsd.port = nil
48
+ @statsd.port.must_equal 8125
23
49
  end
24
50
  end
25
51
 
26
52
  describe "#increment" do
27
53
  it "should format the message according to the statsd spec" do
28
54
  @statsd.increment('foobar')
29
- @statsd.socket.recv.must_equal ['foobar:1|c']
55
+ @socket.recv.must_equal ['foobar:1|c']
30
56
  end
31
57
 
32
58
  describe "with a sample rate" do
33
59
  before { class << @statsd; def rand; 0; end; end } # ensure delivery
34
60
  it "should format the message according to the statsd spec" do
35
61
  @statsd.increment('foobar', 0.5)
36
- @statsd.socket.recv.must_equal ['foobar:1|c|@0.5']
62
+ @socket.recv.must_equal ['foobar:1|c|@0.5']
37
63
  end
38
64
  end
39
65
  end
@@ -41,14 +67,31 @@ describe Statsd do
41
67
  describe "#decrement" do
42
68
  it "should format the message according to the statsd spec" do
43
69
  @statsd.decrement('foobar')
44
- @statsd.socket.recv.must_equal ['foobar:-1|c']
70
+ @socket.recv.must_equal ['foobar:-1|c']
45
71
  end
46
72
 
47
73
  describe "with a sample rate" do
48
74
  before { class << @statsd; def rand; 0; end; end } # ensure delivery
49
75
  it "should format the message according to the statsd spec" do
50
76
  @statsd.decrement('foobar', 0.5)
51
- @statsd.socket.recv.must_equal ['foobar:-1|c|@0.5']
77
+ @socket.recv.must_equal ['foobar:-1|c|@0.5']
78
+ end
79
+ end
80
+ end
81
+
82
+ describe "#gauge" do
83
+ it "should send a message with a 'g' type, per the nearbuy fork" do
84
+ @statsd.gauge('begrutten-suffusion', 536)
85
+ @socket.recv.must_equal ['begrutten-suffusion:536|g']
86
+ @statsd.gauge('begrutten-suffusion', -107.3)
87
+ @socket.recv.must_equal ['begrutten-suffusion:-107.3|g']
88
+ end
89
+
90
+ describe "with a sample rate" do
91
+ before { class << @statsd; def rand; 0; end; end } # ensure delivery
92
+ it "should format the message according to the statsd spec" do
93
+ @statsd.gauge('begrutten-suffusion', 536, 0.1)
94
+ @socket.recv.must_equal ['begrutten-suffusion:536|g|@0.1']
52
95
  end
53
96
  end
54
97
  end
@@ -56,14 +99,14 @@ describe Statsd do
56
99
  describe "#timing" do
57
100
  it "should format the message according to the statsd spec" do
58
101
  @statsd.timing('foobar', 500)
59
- @statsd.socket.recv.must_equal ['foobar:500|ms']
102
+ @socket.recv.must_equal ['foobar:500|ms']
60
103
  end
61
104
 
62
105
  describe "with a sample rate" do
63
106
  before { class << @statsd; def rand; 0; end; end } # ensure delivery
64
107
  it "should format the message according to the statsd spec" do
65
108
  @statsd.timing('foobar', 500, 0.5)
66
- @statsd.socket.recv.must_equal ['foobar:500|ms|@0.5']
109
+ @socket.recv.must_equal ['foobar:500|ms|@0.5']
67
110
  end
68
111
  end
69
112
  end
@@ -71,7 +114,7 @@ describe Statsd do
71
114
  describe "#time" do
72
115
  it "should format the message according to the statsd spec" do
73
116
  @statsd.time('foobar') { sleep(0.001); 'test' }
74
- @statsd.socket.recv.must_equal ['foobar:1|ms']
117
+ @socket.recv.must_equal ['foobar:1|ms']
75
118
  end
76
119
 
77
120
  it "should return the result of the block" do
@@ -84,36 +127,40 @@ describe Statsd do
84
127
 
85
128
  it "should format the message according to the statsd spec" do
86
129
  result = @statsd.time('foobar', 0.5) { sleep(0.001); 'test' }
87
- @statsd.socket.recv.must_equal ['foobar:1|ms|@0.5']
130
+ @socket.recv.must_equal ['foobar:1|ms|@0.5']
88
131
  end
89
132
  end
90
133
  end
91
134
 
92
135
  describe "#sampled" do
93
136
  describe "when the sample rate is 1" do
94
- it "should yield" do
95
- @statsd.sampled(1) { :yielded }.must_equal :yielded
137
+ before { class << @statsd; def rand; raise end; end }
138
+ it "should send" do
139
+ @statsd.timing('foobar', 500, 1)
140
+ @socket.recv.must_equal ['foobar:500|ms']
96
141
  end
97
142
  end
98
143
 
99
144
  describe "when the sample rate is greater than a random value [0,1]" do
100
145
  before { class << @statsd; def rand; 0; end; end } # ensure delivery
101
- it "should yield" do
102
- @statsd.sampled(0.5) { :yielded }.must_equal :yielded
146
+ it "should send" do
147
+ @statsd.timing('foobar', 500, 0.5)
148
+ @socket.recv.must_equal ['foobar:500|ms|@0.5']
103
149
  end
104
150
  end
105
151
 
106
152
  describe "when the sample rate is less than a random value [0,1]" do
107
153
  before { class << @statsd; def rand; 1; end; end } # ensure no delivery
108
- it "should not yield" do
109
- @statsd.sampled(0.5) { :yielded }.must_equal nil
154
+ it "should not send" do
155
+ @statsd.timing('foobar', 500, 0.5).must_equal nil
110
156
  end
111
157
  end
112
158
 
113
159
  describe "when the sample rate is equal to a random value [0,1]" do
114
- before { class << @statsd; def rand; 0.5; end; end } # ensure delivery
115
- it "should yield" do
116
- @statsd.sampled(0.5) { :yielded }.must_equal :yielded
160
+ before { class << @statsd; def rand; 0; end; end } # ensure delivery
161
+ it "should send" do
162
+ @statsd.timing('foobar', 500, 0.5)
163
+ @socket.recv.must_equal ['foobar:500|ms|@0.5']
117
164
  end
118
165
  end
119
166
  end
@@ -123,17 +170,22 @@ describe Statsd do
123
170
 
124
171
  it "should add namespace to increment" do
125
172
  @statsd.increment('foobar')
126
- @statsd.socket.recv.must_equal ['service.foobar:1|c']
173
+ @socket.recv.must_equal ['service.foobar:1|c']
127
174
  end
128
175
 
129
176
  it "should add namespace to decrement" do
130
177
  @statsd.decrement('foobar')
131
- @statsd.socket.recv.must_equal ['service.foobar:-1|c']
178
+ @socket.recv.must_equal ['service.foobar:-1|c']
132
179
  end
133
180
 
134
181
  it "should add namespace to timing" do
135
182
  @statsd.timing('foobar', 500)
136
- @statsd.socket.recv.must_equal ['service.foobar:500|ms']
183
+ @socket.recv.must_equal ['service.foobar:500|ms']
184
+ end
185
+
186
+ it "should add namespace to gauge" do
187
+ @statsd.gauge('foobar', 500)
188
+ @socket.recv.must_equal ['service.foobar:500|g']
137
189
  end
138
190
  end
139
191
 
@@ -156,11 +208,9 @@ describe Statsd do
156
208
 
157
209
  @log.string.must_be_empty
158
210
  end
159
-
160
211
  end
161
212
 
162
213
  describe "stat names" do
163
-
164
214
  it "should accept anything as stat" do
165
215
  @statsd.increment(Object, 1)
166
216
  end
@@ -169,16 +219,45 @@ describe Statsd do
169
219
  class Statsd::SomeClass; end
170
220
  @statsd.increment(Statsd::SomeClass, 1)
171
221
 
172
- @statsd.socket.recv.must_equal ['Statsd.SomeClass:1|c']
222
+ @socket.recv.must_equal ['Statsd.SomeClass:1|c']
173
223
  end
174
224
 
175
225
  it "should replace statsd reserved chars in the stat name" do
176
226
  @statsd.increment('ray@hostname.blah|blah.blah:blah', 1)
177
- @statsd.socket.recv.must_equal ['ray_hostname.blah_blah.blah_blah:1|c']
227
+ @socket.recv.must_equal ['ray_hostname.blah_blah.blah_blah:1|c']
228
+ end
229
+ end
230
+
231
+ describe "handling socket errors" do
232
+ before do
233
+ require 'stringio'
234
+ Statsd.logger = Logger.new(@log = StringIO.new)
235
+ @socket.instance_eval { def send(*) raise SocketError end }
178
236
  end
179
237
 
238
+ it "should ignore socket errors" do
239
+ @statsd.increment('foobar').must_equal nil
240
+ end
241
+
242
+ it "should log socket errors" do
243
+ @statsd.increment('foobar')
244
+ @log.string.must_match 'Statsd: SocketError'
245
+ end
180
246
  end
181
247
 
248
+ describe "thread safety" do
249
+
250
+ it "should use a thread local socket" do
251
+ Thread.current[:statsd_socket].must_equal @socket
252
+ @statsd.send(:socket).must_equal @socket
253
+ end
254
+
255
+ it "should create a new socket when used in a new thread" do
256
+ sock = @statsd.send(:socket)
257
+ Thread.new { Thread.current[:statsd_socket].wont_equal sock }.join
258
+ end
259
+
260
+ end
182
261
  end
183
262
 
184
263
  describe Statsd do
data/statsd-ruby.gemspec CHANGED
@@ -1,57 +1,25 @@
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
2
 
6
- Gem::Specification.new do |s|
7
- s.name = %q{statsd-ruby}
8
- s.version = "0.3.0"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
3
+ Gem::Specification.new("statsd-ruby", "1.0.0") do |s|
11
4
  s.authors = ["Rein Henrichs"]
12
- s.date = %q{2011-06-24}
13
- s.description = %q{A Statsd client in Ruby}
14
- s.email = %q{rein@phpfog.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE.txt",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- "LICENSE.txt",
22
- "README.rdoc",
23
- "Rakefile",
24
- "VERSION",
25
- "lib/statsd.rb",
26
- "spec/helper.rb",
27
- "spec/statsd_spec.rb",
28
- "statsd-ruby.gemspec"
29
- ]
30
- s.homepage = %q{http://github.com/reinh/statsd}
31
- s.licenses = ["MIT"]
32
- s.require_paths = ["lib"]
33
- s.rubygems_version = %q{1.3.9.1}
34
- s.summary = %q{A Statsd client in Ruby}
5
+ s.email = "rein@phpfog.com"
6
+
7
+ s.summary = "A Ruby StatsD client"
8
+ s.description = "A Ruby StatsD client (https://github.com/etsy/statsd)"
35
9
 
36
- if s.respond_to? :specification_version then
37
- s.specification_version = 3
10
+ s.homepage = "https://github.com/reinh/statsd-ruby"
11
+ s.licenses = %w[MIT]
38
12
 
39
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
40
- s.add_development_dependency(%q<minitest>, [">= 0"])
41
- s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
42
- s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
43
- s.add_development_dependency(%q<rcov>, [">= 0"])
44
- else
45
- s.add_dependency(%q<minitest>, [">= 0"])
46
- s.add_dependency(%q<yard>, ["~> 0.6.0"])
47
- s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
48
- s.add_dependency(%q<rcov>, [">= 0"])
49
- end
50
- else
51
- s.add_dependency(%q<minitest>, [">= 0"])
52
- s.add_dependency(%q<yard>, ["~> 0.6.0"])
53
- s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
54
- s.add_dependency(%q<rcov>, [">= 0"])
13
+ s.extra_rdoc_files = %w[LICENSE.txt README.rdoc]
14
+
15
+ if $0 =~ /gem/ # If running under rubygems (building), otherwise, just leave
16
+ s.files = `git ls-files`.split($\)
17
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
55
18
  end
19
+
20
+ s.add_development_dependency "minitest", ">= 3.2.0"
21
+ s.add_development_dependency "yard"
22
+ s.add_development_dependency "simplecov", ">= 0.6.4"
23
+ s.add_development_dependency "rake"
56
24
  end
57
25
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statsd-ruby
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
+ - 1
7
8
  - 0
8
- - 3
9
9
  - 0
10
- version: 0.3.0
10
+ version: 1.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Rein Henrichs
@@ -15,59 +15,57 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-24 00:00:00 -07:00
19
- default_executable:
18
+ date: 2012-07-02 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
- name: minitest
23
21
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
23
  none: false
26
24
  requirements:
27
25
  - - ">="
28
26
  - !ruby/object:Gem::Version
29
- hash: 3
27
+ hash: 15
30
28
  segments:
29
+ - 3
30
+ - 2
31
31
  - 0
32
- version: "0"
32
+ version: 3.2.0
33
+ requirement: *id001
34
+ name: minitest
33
35
  type: :development
34
- version_requirements: *id001
35
36
  - !ruby/object:Gem::Dependency
36
- name: yard
37
37
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
- - - ~>
41
+ - - ">="
42
42
  - !ruby/object:Gem::Version
43
- hash: 7
43
+ hash: 3
44
44
  segments:
45
45
  - 0
46
- - 6
47
- - 0
48
- version: 0.6.0
46
+ version: "0"
47
+ requirement: *id002
48
+ name: yard
49
49
  type: :development
50
- version_requirements: *id002
51
50
  - !ruby/object:Gem::Dependency
52
- name: jeweler
53
51
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
52
+ version_requirements: &id003 !ruby/object:Gem::Requirement
55
53
  none: false
56
54
  requirements:
57
- - - ~>
55
+ - - ">="
58
56
  - !ruby/object:Gem::Version
59
- hash: 7
57
+ hash: 15
60
58
  segments:
61
- - 1
62
- - 5
63
- - 2
64
- version: 1.5.2
59
+ - 0
60
+ - 6
61
+ - 4
62
+ version: 0.6.4
63
+ requirement: *id003
64
+ name: simplecov
65
65
  type: :development
66
- version_requirements: *id003
67
66
  - !ruby/object:Gem::Dependency
68
- name: rcov
69
67
  prerelease: false
70
- requirement: &id004 !ruby/object:Gem::Requirement
68
+ version_requirements: &id004 !ruby/object:Gem::Requirement
71
69
  none: false
72
70
  requirements:
73
71
  - - ">="
@@ -76,9 +74,10 @@ dependencies:
76
74
  segments:
77
75
  - 0
78
76
  version: "0"
77
+ requirement: *id004
78
+ name: rake
79
79
  type: :development
80
- version_requirements: *id004
81
- description: A Statsd client in Ruby
80
+ description: A Ruby StatsD client (https://github.com/etsy/statsd)
82
81
  email: rein@phpfog.com
83
82
  executables: []
84
83
 
@@ -89,16 +88,17 @@ extra_rdoc_files:
89
88
  - README.rdoc
90
89
  files:
91
90
  - .document
91
+ - .gitignore
92
+ - .travis.yml
93
+ - Gemfile
92
94
  - LICENSE.txt
93
95
  - README.rdoc
94
96
  - Rakefile
95
- - VERSION
96
97
  - lib/statsd.rb
97
98
  - spec/helper.rb
98
99
  - spec/statsd_spec.rb
99
100
  - statsd-ruby.gemspec
100
- has_rdoc: true
101
- homepage: http://github.com/reinh/statsd
101
+ homepage: https://github.com/reinh/statsd-ruby
102
102
  licenses:
103
103
  - MIT
104
104
  post_install_message:
@@ -127,9 +127,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
127
  requirements: []
128
128
 
129
129
  rubyforge_project:
130
- rubygems_version: 1.3.9.1
130
+ rubygems_version: 1.8.15
131
131
  signing_key:
132
132
  specification_version: 3
133
- summary: A Statsd client in Ruby
134
- test_files: []
135
-
133
+ summary: A Ruby StatsD client
134
+ test_files:
135
+ - spec/helper.rb
136
+ - spec/statsd_spec.rb
137
+ has_rdoc:
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.3.0