statsd-ruby 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/lib/statsd.rb +39 -11
  3. data/statsd-ruby.gemspec +1 -1
  4. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
data/lib/statsd.rb CHANGED
@@ -2,16 +2,23 @@ require 'socket'
2
2
 
3
3
  # = Statsd: A Statsd client (https://github.com/etsy/statsd)
4
4
  #
5
- # Example:
6
- #
7
- # statsd = Statsd.new 'localhost', 8125
8
- #
9
- # statsd.increment 'garets'
10
- # statsd.timing 'glork', 320
5
+ # @example Set up a global Statsd client for a server on localhost:9125
6
+ # $statsd = Statsd.new 'localhost', 8125
7
+ # @example Send some stats
8
+ # $statsd.increment 'garets'
9
+ # $statsd.timing 'glork', 320
10
+ # @example Use {#time} to time the execution of a block
11
+ # $statsd.time('account.activate') { @account.activate! }
12
+ # @example Create a namespaced statsd client and increment 'account.activate'
13
+ # statsd = Statsd.new('localhost').tap{|sd| sd.namespace = 'account'}
14
+ # statsd.increment 'activate'
11
15
  class Statsd
16
+ # A namespace to prepend to all statsd calls.
12
17
  attr_accessor :namespace
13
18
 
14
19
  class << self
20
+ # Set to any standard logger instance (including stdlib's Logger) to enable
21
+ # stat logging using logger.debug
15
22
  attr_accessor :logger
16
23
  end
17
24
 
@@ -21,24 +28,45 @@ class Statsd
21
28
  @host, @port = host, port
22
29
  end
23
30
 
24
- # @param [String] stat stat name
25
- # @param [Integer] sample_rate sample rate, 1 for always
31
+ # Sends an increment (count = 1) for the given stat to the statsd server.
32
+ #
33
+ # @param stat (see #count)
34
+ # @param sample_rate (see #count)
35
+ # @see #count
26
36
  def increment(stat, sample_rate=1); count stat, 1, sample_rate end
27
37
 
28
- # @param [String] stat stat name
29
- # @param [Integer] sample_rate sample rate, 1 for always
38
+ # Sends a decrement (count = -1) for the given stat to the statsd server.
39
+ #
40
+ # @param stat (see #count)
41
+ # @param sample_rate (see #count)
42
+ # @see #count
30
43
  def decrement(stat, sample_rate=1); count stat, -1, sample_rate end
31
44
 
45
+ # Sends an arbitrary count for the given stat to the statsd server.
46
+ #
32
47
  # @param [String] stat stat name
33
48
  # @param [Integer] count count
34
49
  # @param [Integer] sample_rate sample rate, 1 for always
35
50
  def count(stat, count, sample_rate=1); send stat, count, 'c', sample_rate end
36
51
 
37
- # @param [String] stat stat name
52
+ # Sends a timing (in ms) for the given stat to the statsd server. The
53
+ # sample_rate determines what percentage of the time this report is sent. The
54
+ # statsd server then uses the sample_rate to correctly track the average
55
+ # timing for the stat.
56
+ #
57
+ # @param stat stat name
38
58
  # @param [Integer] ms timing in milliseconds
39
59
  # @param [Integer] sample_rate sample rate, 1 for always
40
60
  def timing(stat, ms, sample_rate=1); send stat, ms, 'ms', sample_rate end
41
61
 
62
+ # Reports execution time of the provided block using {#timing}.
63
+ #
64
+ # @param stat (see #timing)
65
+ # @param sample_rate (see #timing)
66
+ # @yield The operation to be timed
67
+ # @see #timing
68
+ # @example Report the time (in ms) taken to activate an account
69
+ # $statsd.time('account.activate') { @account.activate! }
42
70
  def time(stat, sample_rate=1)
43
71
  start = Time.now
44
72
  result = yield
data/statsd-ruby.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{statsd-ruby}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Rein Henrichs"]
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: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Rein Henrichs