statsd-ruby-tcp 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc28eb77eab12c095568880db2af25264531491ce58ff14edd610b3ae53ab288
4
- data.tar.gz: 19563dd10cf68001818377919e34537a2973500820367b0aa93fa78cc1aadea8
3
+ metadata.gz: 4ccd5371be8f0fa5a26268f59601961d9182065ef9a9d1053ab6605dce11772b
4
+ data.tar.gz: b5cdb9fc7980e0eb1191eb925da266f996a5d15bb43e25640061c6d09db7a87f
5
5
  SHA512:
6
- metadata.gz: ff91b840bae222b9dd6a7e237d25f83ffee79c91cc32b0d2bd5bf55d49a460815d571ff2d7eb24b951b008d6c37dfb81e645289b486a42558fc71903dc293ee8
7
- data.tar.gz: d141ada3e73e42d85f494c41067fda5d8e209d686e2cd20c4d1c4c94e83b2840b7419b9297d4855412e12a9213247b78e9d503a2dc2cab04cce6860219aa084d
6
+ metadata.gz: 48f6a375acfcecde102ebaff454cf4c08e80331ccaba4179648c817ef9a97076fd2ad504e262a53d6b0cacbd1c287a270a2f904746e7c01d7db2ec71889c7f27
7
+ data.tar.gz: 2f987d662b65ab4d5673029e5b4f46710f6bab794d2fbb6bb16cd1e29ce65cba2faaf36fb805ee30c75e3276ce559ddab11590d7b893e12b15b2471a9e1c6751
@@ -9,11 +9,11 @@ Bundler:
9
9
 
10
10
  = Basic Usage
11
11
 
12
- # Set up a global Statsd client for a server on localhost:9125
13
- $statsd = Statsd.new 'localhost', 9125
12
+ # Set up a global StatsdTcp client for a server on localhost:9125
13
+ $statsd = StatsdTcp.new 'localhost', 9125
14
14
 
15
- # Set up a global Statsd client for a server on IPv6 port 9125
16
- $statsd = Statsd.new '::1', 9125
15
+ # Set up a global StatsdTcp client for a server on IPv6 port 9125
16
+ $statsd = StatsdTcp.new '::1', 9125
17
17
 
18
18
  # Send some stats
19
19
  $statsd.increment 'garets'
@@ -24,7 +24,7 @@ Bundler:
24
24
  $statsd.time('account.activate') { @account.activate! }
25
25
 
26
26
  # Create a namespaced statsd client and increment 'account.activate'
27
- statsd = Statsd.new('localhost').tap{|sd| sd.namespace = 'account'}
27
+ statsd = StatsdTcp.new('localhost').tap{|sd| sd.namespace = 'account'}
28
28
  statsd.increment 'activate'
29
29
 
30
30
  = Testing
@@ -4,12 +4,12 @@ require 'json'
4
4
 
5
5
  require 'statsd/monotonic_time'
6
6
 
7
- # = Statsd: A Statsd client (https://github.com/etsy/statsd)
7
+ # = StatsdTcp: A StatsdTcp client (https://github.com/etsy/statsd)
8
8
  #
9
- # @example Set up a global Statsd client for a server on localhost:8125
10
- # $statsd = Statsd.new 'localhost', 8125
11
- # @example Set up a global Statsd client for a server on IPv6 port 8125
12
- # $statsd = Statsd.new '::1', 8125
9
+ # @example Set up a global StatsdTcp client for a server on localhost:8125
10
+ # $statsd = StatsdTcp.new 'localhost', 8125
11
+ # @example Set up a global StatsdTcp client for a server on IPv6 port 8125
12
+ # $statsd = StatsdTcp.new '::1', 8125
13
13
  # @example Send some stats
14
14
  # $statsd.increment 'garets'
15
15
  # $statsd.timing 'glork', 320
@@ -17,34 +17,34 @@ require 'statsd/monotonic_time'
17
17
  # @example Use {#time} to time the execution of a block
18
18
  # $statsd.time('account.activate') { @account.activate! }
19
19
  # @example Create a namespaced statsd client and increment 'account.activate'
20
- # statsd = Statsd.new('localhost').tap{|sd| sd.namespace = 'account'}
20
+ # statsd = StatsdTcp.new('localhost').tap{|sd| sd.namespace = 'account'}
21
21
  # statsd.increment 'activate'
22
22
  #
23
- # Statsd instances are thread safe for general usage, by utilizing the thread
23
+ # StatsdTcp instances are thread safe for general usage, by utilizing the thread
24
24
  # safe nature of UDP sends. The attributes are stateful, and are not
25
25
  # mutexed, it is expected that users will not change these at runtime in
26
26
  # threaded environments. If users require such use cases, it is recommend that
27
- # users either mutex around their Statsd object, or create separate objects for
27
+ # users either mutex around their StatsdTcp object, or create separate objects for
28
28
  # each namespace / host+port combination.
29
- class Statsd
29
+ class StatsdTcp
30
30
 
31
31
  # = Batch: A batching statsd proxy
32
32
  #
33
33
  # @example Batch a set of instruments using Batch and manual flush:
34
- # $statsd = Statsd.new 'localhost', 8125
35
- # batch = Statsd::Batch.new($statsd)
34
+ # $statsd = StatsdTcp.new 'localhost', 8125
35
+ # batch = StatsdTcp::Batch.new($statsd)
36
36
  # batch.increment 'garets'
37
37
  # batch.timing 'glork', 320
38
38
  # batch.gauge 'bork', 100
39
39
  # batch.flush
40
40
  #
41
- # Batch is a subclass of Statsd, but with a constructor that proxies to a
42
- # normal Statsd instance. It has it's own batch_size and namespace parameters
43
- # (that inherit defaults from the supplied Statsd instance). It is recommended
41
+ # Batch is a subclass of StatsdTcp, but with a constructor that proxies to a
42
+ # normal StatsdTcp instance. It has it's own batch_size and namespace parameters
43
+ # (that inherit defaults from the supplied StatsdTcp instance). It is recommended
44
44
  # that some care is taken if setting very large batch sizes. If the batch size
45
45
  # exceeds the allowed packet size for UDP on your network, communication
46
46
  # troubles may occur and data will be lost.
47
- class Batch < Statsd
47
+ class Batch < StatsdTcp
48
48
 
49
49
  extend Forwardable
50
50
  def_delegators :@statsd,
@@ -57,7 +57,7 @@ class Statsd
57
57
 
58
58
  attr_accessor :batch_size, :batch_byte_size, :flush_interval
59
59
 
60
- # @param [Statsd] statsd requires a configured Statsd instance
60
+ # @param [StatsdTcp] statsd requires a configured StatsdTcp instance
61
61
  def initialize(statsd)
62
62
  @statsd = statsd
63
63
  @batch_size = statsd.batch_size
@@ -236,10 +236,10 @@ class Statsd
236
236
  end
237
237
 
238
238
  def send_to_socket(message)
239
- self.class.logger.debug { "Statsd: #{message}" } if self.class.logger
239
+ self.class.logger.debug { "StatsdTcp: #{message}" } if self.class.logger
240
240
  @socket.write(message.to_s + "\n")
241
241
  rescue => boom
242
- self.class.logger.error { "Statsd: #{boom.class} #{boom}" } if self.class.logger
242
+ self.class.logger.error { "StatsdTcp: #{boom.class} #{boom}" } if self.class.logger
243
243
  nil
244
244
  end
245
245
 
@@ -468,7 +468,7 @@ class Statsd
468
468
  protected
469
469
 
470
470
  def send_to_socket(message)
471
- self.class.logger.debug { "Statsd: #{message}" } if self.class.logger
471
+ self.class.logger.debug { "StatsdTcp: #{message}" } if self.class.logger
472
472
 
473
473
  retries = 0
474
474
  n = 0
@@ -490,7 +490,7 @@ class Statsd
490
490
  end
491
491
  n
492
492
  rescue => boom
493
- self.class.logger.error { "Statsd: #{boom.class} #{boom}" } if self.class.logger
493
+ self.class.logger.error { "StatsdTcp: #{boom.class} #{boom}" } if self.class.logger
494
494
  nil
495
495
  end
496
496
 
@@ -1,4 +1,4 @@
1
- class Statsd
1
+ class StatsdTcp
2
2
  # = MonotonicTime: a helper for getting monotonic time
3
3
  #
4
4
  # @example
@@ -1,9 +1,9 @@
1
1
  require 'helper'
2
2
 
3
- describe Statsd::Admin do
3
+ describe StatsdTcp::Admin do
4
4
 
5
5
  before do
6
- class Statsd::Admin
6
+ class StatsdTcp::Admin
7
7
  o, $VERBOSE = $VERBOSE, nil
8
8
  alias connect_old connect
9
9
  def connect
@@ -12,12 +12,12 @@ describe Statsd::Admin do
12
12
  end
13
13
  $VERBOSE = o
14
14
  end
15
- @admin = Statsd::Admin.new('localhost', 1234)
15
+ @admin = StatsdTcp::Admin.new('localhost', 1234)
16
16
  @socket = @admin.instance_variable_set(:@socket, FakeTCPSocket.new)
17
17
  end
18
18
 
19
19
  after do
20
- class Statsd::Admin
20
+ class StatsdTcp::Admin
21
21
  o, $VERBOSE = $VERBOSE, nil
22
22
  alias connect connect_old
23
23
  $VERBOSE = o
@@ -31,7 +31,7 @@ describe Statsd::Admin do
31
31
  end
32
32
 
33
33
  it "should default the host to 127.0.0.1 and port to 8126" do
34
- statsd = Statsd::Admin.new
34
+ statsd = StatsdTcp::Admin.new
35
35
  statsd.host.must_equal '127.0.0.1'
36
36
  statsd.port.must_equal 8126
37
37
  end
@@ -1,8 +1,8 @@
1
1
  require 'helper'
2
2
 
3
- describe Statsd do
3
+ describe StatsdTcp do
4
4
  before do
5
- class Statsd
5
+ class StatsdTcp
6
6
  o, $VERBOSE = $VERBOSE, nil
7
7
  alias connect_old connect
8
8
  def connect
@@ -12,12 +12,12 @@ describe Statsd do
12
12
  $VERBOSE = o
13
13
  end
14
14
 
15
- @statsd = Statsd.new('localhost', 1234)
15
+ @statsd = StatsdTcp.new('localhost', 1234)
16
16
  @socket = @statsd.instance_variable_set(:@socket, FakeUDPSocket.new)
17
17
  end
18
18
 
19
19
  after do
20
- class Statsd
20
+ class StatsdTcp
21
21
  o, $VERBOSE = $VERBOSE, nil
22
22
  alias connect connect_old
23
23
  $VERBOSE = o
@@ -31,7 +31,7 @@ describe Statsd do
31
31
  end
32
32
 
33
33
  it "should default the host to 127.0.0.1 and port to 8125" do
34
- statsd = Statsd.new
34
+ statsd = StatsdTcp.new
35
35
  statsd.host.must_equal '127.0.0.1'
36
36
  statsd.port.must_equal 8125
37
37
  end
@@ -287,18 +287,18 @@ describe Statsd do
287
287
 
288
288
  describe "with logging" do
289
289
  require 'stringio'
290
- before { Statsd.logger = Logger.new(@log = StringIO.new)}
290
+ before { StatsdTcp.logger = Logger.new(@log = StringIO.new)}
291
291
 
292
292
  it "should write to the log in debug" do
293
- Statsd.logger.level = Logger::DEBUG
293
+ StatsdTcp.logger.level = Logger::DEBUG
294
294
 
295
295
  @statsd.increment('foobar')
296
296
 
297
- @log.string.must_match "Statsd: foobar:1|c"
297
+ @log.string.must_match "StatsdTcp: foobar:1|c"
298
298
  end
299
299
 
300
300
  it "should not write to the log unless debug" do
301
- Statsd.logger.level = Logger::INFO
301
+ StatsdTcp.logger.level = Logger::INFO
302
302
 
303
303
  @statsd.increment('foobar')
304
304
 
@@ -312,10 +312,10 @@ describe Statsd do
312
312
  end
313
313
 
314
314
  it "should replace ruby constant delimeter with graphite package name" do
315
- class Statsd::SomeClass; end
316
- @statsd.increment(Statsd::SomeClass, 1)
315
+ class StatsdTcp::SomeClass; end
316
+ @statsd.increment(StatsdTcp::SomeClass, 1)
317
317
 
318
- @socket.recv.must_equal ['Statsd.SomeClass:1|c']
318
+ @socket.recv.must_equal ['StatsdTcp.SomeClass:1|c']
319
319
  end
320
320
 
321
321
  describe "custom delimiter" do
@@ -324,10 +324,10 @@ describe Statsd do
324
324
  end
325
325
 
326
326
  it "should replace ruby constant delimiter with custom delimiter" do
327
- class Statsd::SomeOtherClass; end
328
- @statsd.increment(Statsd::SomeOtherClass, 1)
327
+ class StatsdTcp::SomeOtherClass; end
328
+ @statsd.increment(StatsdTcp::SomeOtherClass, 1)
329
329
 
330
- @socket.recv.must_equal ['Statsd-SomeOtherClass:1|c']
330
+ @socket.recv.must_equal ['StatsdTcp-SomeOtherClass:1|c']
331
331
  end
332
332
  end
333
333
 
@@ -340,7 +340,7 @@ describe Statsd do
340
340
  describe "handling socket errors" do
341
341
  before do
342
342
  require 'stringio'
343
- Statsd.logger = Logger.new(@log = StringIO.new)
343
+ StatsdTcp.logger = Logger.new(@log = StringIO.new)
344
344
  @socket.instance_eval { def write(*) raise SocketError end }
345
345
  end
346
346
 
@@ -350,7 +350,7 @@ describe Statsd do
350
350
 
351
351
  it "should log socket errors" do
352
352
  @statsd.increment('foobar')
353
- @log.string.must_match 'Statsd: SocketError'
353
+ @log.string.must_match 'StatsdTcp: SocketError'
354
354
  end
355
355
  end
356
356
 
@@ -450,7 +450,7 @@ describe Statsd do
450
450
  end
451
451
 
452
452
  it "should not flush to the socket if the backlog is empty" do
453
- batch = Statsd::Batch.new(@statsd)
453
+ batch = StatsdTcp::Batch.new(@statsd)
454
454
  batch.flush
455
455
  @socket.recv.must_be :nil?
456
456
 
@@ -460,19 +460,19 @@ describe Statsd do
460
460
  end
461
461
 
462
462
  it "should support setting namespace for the underlying instance" do
463
- batch = Statsd::Batch.new(@statsd)
463
+ batch = StatsdTcp::Batch.new(@statsd)
464
464
  batch.namespace = 'ns'
465
465
  @statsd.namespace.must_equal 'ns'
466
466
  end
467
467
 
468
468
  it "should support setting host for the underlying instance" do
469
- batch = Statsd::Batch.new(@statsd)
469
+ batch = StatsdTcp::Batch.new(@statsd)
470
470
  batch.host = '1.2.3.4'
471
471
  @statsd.host.must_equal '1.2.3.4'
472
472
  end
473
473
 
474
474
  it "should support setting port for the underlying instance" do
475
- batch = Statsd::Batch.new(@statsd)
475
+ batch = StatsdTcp::Batch.new(@statsd)
476
476
  batch.port = 42
477
477
  @statsd.port.must_equal 42
478
478
  end
@@ -489,7 +489,7 @@ describe Statsd do
489
489
 
490
490
  end
491
491
 
492
- describe Statsd do
492
+ describe StatsdTcp do
493
493
  describe "with a real UDP socket" do
494
494
  it "should actually send stuff over the socket" do
495
495
  family = Addrinfo.udp(UDPSocket.getaddress('localhost'), 0).afamily
@@ -499,7 +499,7 @@ describe Statsd do
499
499
  socket.bind(host, port)
500
500
  port = socket.addr[1]
501
501
 
502
- statsd = Statsd.new(host, port)
502
+ statsd = StatsdTcp.new(host, port)
503
503
  statsd.increment('foobar')
504
504
  message = socket.recvfrom(16).first
505
505
  message.must_equal 'foobar:1|c'
@@ -515,7 +515,7 @@ describe Statsd do
515
515
  socket.bind(host, port)
516
516
  port = socket.addr[1]
517
517
 
518
- statsd = Statsd.new(host, port)
518
+ statsd = StatsdTcp.new(host, port)
519
519
  statsd.increment('foobar')
520
520
  message = socket.recvfrom(16).first
521
521
  message.must_equal 'foobar:1|c'
@@ -531,7 +531,7 @@ describe Statsd do
531
531
  socket.bind(host, port)
532
532
  port = socket.addr[1]
533
533
 
534
- statsd = Statsd.new(host, port)
534
+ statsd = StatsdTcp.new(host, port)
535
535
  statsd.increment('foobar')
536
536
  message = socket.recvfrom(16).first
537
537
  message.must_equal 'foobar:1|c'
@@ -551,7 +551,7 @@ describe Statsd do
551
551
  socket = nil
552
552
  Thread.new { socket = server.accept }
553
553
 
554
- statsd = Statsd.new(host, port, :tcp)
554
+ statsd = StatsdTcp.new(host, port, :tcp)
555
555
  statsd.increment('foobar')
556
556
 
557
557
  Timeout.timeout(5) do
@@ -575,7 +575,7 @@ describe Statsd do
575
575
  socket = nil
576
576
  Thread.new { socket = server.accept }
577
577
 
578
- statsd = Statsd.new(host, port, :tcp)
578
+ statsd = StatsdTcp.new(host, port, :tcp)
579
579
  statsd.increment('foobar')
580
580
 
581
581
  Timeout.timeout(5) do
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- Gem::Specification.new("statsd-ruby-tcp", "0.1.0") do |s|
3
+ Gem::Specification.new("statsd-ruby-tcp", "0.1.1") do |s|
4
4
  s.authors = `git log --format='%aN' | sort -u`.split("\n")
5
5
  s.email = "reinh@reinh.com"
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statsd-ruby-tcp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Agis Anastasopoulos