statsd-instrument 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -20,6 +20,7 @@ This is the same as what Etsy uses (mentioned in the README for http://github.co
20
20
  StatsD.server = 'statsd.myservice.com:8125'
21
21
  StatsD.logger = Rails.logger
22
22
  StatsD.mode = :production
23
+ StatsD.default_sample_rate = 0.1 # Sample 10% of events. By default all events are reported.
23
24
  ```
24
25
 
25
26
  If you set the mode to anything besides production then the library will print its calls to the logger, rather than sending them over the wire.
@@ -123,3 +124,11 @@ GoogleBase.statsd_count_success :insert, 'GoogleBase.insert' do |response|
123
124
  end
124
125
  ```
125
126
 
127
+ ### Instrumenting Class Methods
128
+
129
+ You can instrument class methods, just like instance methods, using the metaprogramming methods. You simply have to configure the instrumentation on the singleton class of the Class you want to instrument.
130
+
131
+ ```ruby
132
+ AWS::S3::Base.singleton_class.extend StatsD::Instrument
133
+ AWS::S3::Base.singleton_class.statsd_measure :request, 'S3.request'
134
+ ```
@@ -1,11 +1,13 @@
1
1
  require 'socket'
2
+ require 'benchmark'
2
3
 
3
4
  module StatsD
4
5
  class << self
5
- attr_accessor :host, :port, :mode, :logger, :enabled
6
+ attr_accessor :host, :port, :mode, :logger, :enabled, :default_sample_rate
6
7
  end
7
8
  self.enabled = true
8
-
9
+ self.default_sample_rate = 1
10
+
9
11
  # StatsD.server = 'localhost:1234'
10
12
  def self.server=(conn)
11
13
  self.host, port = conn.split(':')
@@ -88,16 +90,16 @@ module StatsD
88
90
  # glork:320|ms
89
91
  def self.measure(key, milli = nil)
90
92
  result = nil
91
- ms = Benchmark.ms do
93
+ ms = milli || Benchmark.ms do
92
94
  result = yield
93
- end if milli.nil?
95
+ end
94
96
 
95
97
  write(key, ms, :ms)
96
98
  result
97
99
  end
98
100
 
99
101
  # gorets:1|c
100
- def self.increment(key, delta = 1, sample_rate = 1)
102
+ def self.increment(key, delta = 1, sample_rate = default_sample_rate)
101
103
  write(key, delta, :incr, sample_rate)
102
104
  end
103
105
 
@@ -107,7 +109,7 @@ module StatsD
107
109
  @socket ||= UDPSocket.new
108
110
  end
109
111
 
110
- def self.write(k,v,op, sample_rate = 1)
112
+ def self.write(k,v,op, sample_rate = default_sample_rate)
111
113
  return unless enabled
112
114
  return if sample_rate < 1 && rand > sample_rate
113
115
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "statsd-instrument"
3
- s.version = '1.0.1'
3
+ s.version = '1.1.0'
4
4
  s.authors = ["Jesse Storimer"]
5
5
  s.email = ["jesse@shopify.com"]
6
6
  s.homepage = "http://github.com/shopify/statsd-instrument"
@@ -147,4 +147,10 @@ class StatsDTest < Test::Unit::TestCase
147
147
  StatsD.increment('fooz')
148
148
  StatsD.enabled = true
149
149
  end
150
+
151
+ def test_statsd_measure_with_explicit_value
152
+ StatsD.expects(:write).with('values.foobar', 42, :ms)
153
+
154
+ StatsD.measure('values.foobar', 42)
155
+ end
150
156
  end
metadata CHANGED
@@ -1,47 +1,35 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: statsd-instrument
3
- version: !ruby/object:Gem::Version
4
- hash: 21
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- - 1
10
- version: 1.0.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Jesse Storimer
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-08-15 00:00:00 -04:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2011-11-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: mocha
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2156605620 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
33
22
  type: :development
34
- version_requirements: *id001
35
- description: A StatsD client for Ruby apps. Provides metaprogramming methods to inject StatsD instrumentation into your code.
36
- email:
23
+ prerelease: false
24
+ version_requirements: *2156605620
25
+ description: A StatsD client for Ruby apps. Provides metaprogramming methods to inject
26
+ StatsD instrumentation into your code.
27
+ email:
37
28
  - jesse@shopify.com
38
29
  executables: []
39
-
40
30
  extensions: []
41
-
42
31
  extra_rdoc_files: []
43
-
44
- files:
32
+ files:
45
33
  - .gitignore
46
34
  - Gemfile
47
35
  - LICENSE
@@ -51,39 +39,30 @@ files:
51
39
  - lib/statsd/instrument.rb
52
40
  - statsd-instrument.gemspec
53
41
  - test/statsd-instrument_test.rb
54
- has_rdoc: true
55
42
  homepage: http://github.com/shopify/statsd-instrument
56
43
  licenses: []
57
-
58
44
  post_install_message:
59
45
  rdoc_options: []
60
-
61
- require_paths:
46
+ require_paths:
62
47
  - lib
63
- required_ruby_version: !ruby/object:Gem::Requirement
48
+ required_ruby_version: !ruby/object:Gem::Requirement
64
49
  none: false
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- hash: 3
69
- segments:
70
- - 0
71
- version: "0"
72
- required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
55
  none: false
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- hash: 3
78
- segments:
79
- - 0
80
- version: "0"
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
81
60
  requirements: []
82
-
83
61
  rubyforge_project:
84
- rubygems_version: 1.6.2
62
+ rubygems_version: 1.8.11
85
63
  signing_key:
86
64
  specification_version: 3
87
65
  summary: A StatsD client for Ruby apps
88
- test_files:
66
+ test_files:
89
67
  - test/statsd-instrument_test.rb
68
+ has_rdoc: