dogstatsd-ruby 1.1.0 → 1.2.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.
Files changed (3) hide show
  1. data/README.md +4 -1
  2. data/lib/statsd.rb +26 -8
  3. metadata +3 -3
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  dogstatsd-ruby
3
3
  ==============
4
4
 
5
- A client for DogStatsd, an extension of the Statsd metric server for Datadog.
5
+ A client for DogStatsD, an extension of the StatsD metric server for Datadog.
6
6
 
7
7
  [![Build Status](https://secure.travis-ci.org/DataDog/dogstatsd-ruby.png)](http://travis-ci.org/DataDog/dogstatsd-ruby)
8
8
 
@@ -56,6 +56,9 @@ Change Log
56
56
  ----------
57
57
 
58
58
 
59
+ - 1.2.0
60
+ - Added global tags.
61
+ - Added ability to set `namespace` and `tags` from `Statsd#initialize`.
59
62
  - 1.1.0
60
63
  - Added `sets` metrics.
61
64
  - 1.0.0
@@ -12,17 +12,26 @@ require 'socket'
12
12
  # @example Use {#time} to time the execution of a block
13
13
  # $statsd.time('account.activate') { @account.activate! }
14
14
  # @example Create a namespaced statsd client and increment 'account.activate'
15
- # statsd = Statsd.new('localhost').tap{|sd| sd.namespace = 'account'}
15
+ # statsd = Statsd.new 'localhost', 8125, :namespace => 'account'
16
16
  # statsd.increment 'activate'
17
+ # @example Create a statsd client with global tags
18
+ # statsd = Statsd.new 'localhost', 8125, :tags => 'tag1:true'
17
19
  class Statsd
18
- # A namespace to prepend to all statsd calls.
20
+
21
+ DEFAULT_HOST = '127.0.0.1'
22
+ DEFAULT_PORT = 8125
23
+
24
+ # A namespace to prepend to all statsd calls. Defaults to no namespace.
19
25
  attr_reader :namespace
20
26
 
21
27
  # StatsD host. Defaults to 127.0.0.1.
22
- attr_accessor :host
28
+ attr_reader :host
23
29
 
24
30
  # StatsD port. Defaults to 8125.
25
- attr_accessor :port
31
+ attr_reader :port
32
+
33
+ # Global tags to be added to every statsd call. Defaults to no tags.
34
+ attr_reader :tags
26
35
 
27
36
  class << self
28
37
  # Set to a standard logger instance to enable debug logging.
@@ -31,20 +40,24 @@ class Statsd
31
40
 
32
41
  # Return the current version of the library.
33
42
  def self.VERSION
34
- "1.1.0"
43
+ "1.2.0"
35
44
  end
36
45
 
37
46
  # @param [String] host your statsd host
38
47
  # @param [Integer] port your statsd port
39
- def initialize(host = '127.0.0.1', port = 8125)
48
+ # @option opts [String] :namespace set a namespace to be prepended to every metric name
49
+ # @option opts [Array<String>] :tags tags to be added to every metric
50
+ def initialize(host = DEFAULT_HOST, port = DEFAULT_PORT, opts = {})
40
51
  self.host, self.port = host, port
41
52
  @prefix = nil
42
53
  @socket = UDPSocket.new
54
+ self.namespace = opts[:namespace]
55
+ self.tags = opts[:tags]
43
56
  end
44
57
 
45
58
  def namespace=(namespace) #:nodoc:
46
59
  @namespace = namespace
47
- @prefix = "#{namespace}."
60
+ @prefix = namespace.nil? ? nil : "#{namespace}."
48
61
  end
49
62
 
50
63
  def host=(host) #:nodoc:
@@ -55,6 +68,10 @@ class Statsd
55
68
  @port = port || 8125
56
69
  end
57
70
 
71
+ def tags=(tags) #:nodoc:
72
+ @tags = tags || []
73
+ end
74
+
58
75
  # Sends an increment (count = 1) for the given stat to the statsd server.
59
76
  #
60
77
  # @param [String] stat stat name
@@ -169,7 +186,8 @@ class Statsd
169
186
  # Replace Ruby module scoping with '.' and reserved chars (: | @) with underscores.
170
187
  stat = stat.to_s.gsub('::', '.').tr(':|@', '_')
171
188
  rate = "|@#{sample_rate}" unless sample_rate == 1
172
- tags = "|##{opts[:tags].join(",")}" if opts[:tags]
189
+ ts = (tags || []) + (opts[:tags] || [])
190
+ tags = "|##{ts.join(",")}" unless ts.empty?
173
191
  send_to_socket "#{@prefix}#{stat}:#{delta}|#{type}#{rate}#{tags}"
174
192
  end
175
193
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dogstatsd-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-21 00:00:00.000000000 Z
12
+ date: 2013-07-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  version: '0'
108
108
  requirements: []
109
109
  rubyforge_project:
110
- rubygems_version: 1.8.24
110
+ rubygems_version: 1.8.23
111
111
  signing_key:
112
112
  specification_version: 3
113
113
  summary: A Ruby DogStatsd client