statsd-instrument 2.0.0beta2 → 2.0.0

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
  SHA1:
3
- metadata.gz: 0754302b0628e373af2d790101ab5e9d687494d8
4
- data.tar.gz: 8cf3646796b5b0e7569f772e0da663d442f58cf9
3
+ metadata.gz: df07f54f21bc51b1793083e995d51930bff84567
4
+ data.tar.gz: f27b3ff3d202efa2318959385113ca8f60b226b1
5
5
  SHA512:
6
- metadata.gz: 816a88ac56220bb3da7f947f8d462c6ca14c5debe3d5c011a03cb3cbc4aa1e832088585dc0430efa8dfa5ec9f138a268505f41ca8a85ecaf63c981f316905398
7
- data.tar.gz: 49283deaa25ce88057610481c8efe052a4cd847c43bf39399934f432cd177546868096fb6780bb02107c2371c80e4ca4fe8a5065ad1a334683d07d44e2a990a3
6
+ metadata.gz: 0f71108f720c172543a5eecac8535f95f158285d9ff2642b8ae1be02deaba2ebb04e0ed760403efc0388d669b61279d63932fc0eb92e97ac920bf2717ea74ea6
7
+ data.tar.gz: f3f388d3df40ec9539c2d456291e18ff0a28fb43549b84be6f21832ae178682c222a81689fd6f96814494ef649500d3a693e78d4f00bc6be74b5ae340eca0889
@@ -1,5 +1,5 @@
1
1
  module StatsD
2
2
  module Instrument
3
- VERSION = "2.0.0beta2"
3
+ VERSION = "2.0.0"
4
4
  end
5
5
  end
@@ -1,5 +1,4 @@
1
1
  require 'socket'
2
- require 'benchmark'
3
2
  require 'logger'
4
3
 
5
4
  module StatsD
@@ -9,6 +8,20 @@ module StatsD
9
8
  metric_name.respond_to?(:call) ? metric_name.call(callee, args).gsub('::', '.') : metric_name.gsub('::', '.')
10
9
  end
11
10
 
11
+ if Process.respond_to?(:clock_gettime)
12
+ def self.duration
13
+ start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
14
+ yield
15
+ Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
16
+ end
17
+ else
18
+ def self.duration
19
+ start = Time.now
20
+ yield
21
+ Time.now - start
22
+ end
23
+ end
24
+
12
25
  def statsd_measure(method, name, *metric_options)
13
26
  add_to_method(method, name, :measure) do |old_method, new_method, metric_name, *args|
14
27
  define_method(new_method) do |*args, &block|
@@ -123,7 +136,7 @@ module StatsD
123
136
  end
124
137
 
125
138
  result = nil
126
- value = 1000 * Benchmark.realtime { result = block.call } if block_given?
139
+ value = 1000 * StatsD::Instrument.duration { result = block.call } if block_given?
127
140
  metric = collect_metric(hash_argument(metric_options).merge(type: :ms, name: key, value: value))
128
141
  result = metric unless block_given?
129
142
  result
@@ -169,8 +182,8 @@ module StatsD
169
182
  hash = {}
170
183
  args.each_with_index do |value, index|
171
184
  hash[order[index]] = value
172
- end
173
-
185
+ end
186
+
174
187
  return hash
175
188
  end
176
189
 
data/test/statsd_test.rb CHANGED
@@ -19,12 +19,12 @@ class StatsDTest < Minitest::Test
19
19
 
20
20
  def test_statsd_measure_with_explicit_value_and_sample_rate
21
21
  metric = capture_statsd_call { StatsD.measure('values.foobar', 42, :sample_rate => 0.1) }
22
- assert_equal 0.1, metric.sample_rate
22
+ assert_equal 0.1, metric.sample_rate
23
23
  end
24
24
 
25
25
  def test_statsd_measure_with_benchmarked_duration
26
- Benchmark.stubs(:realtime).returns(1.12)
27
- metric = capture_statsd_call do
26
+ StatsD::Instrument.stubs(:duration).returns(1.12)
27
+ metric = capture_statsd_call do
28
28
  StatsD.measure('values.foobar') { 'foo' }
29
29
  end
30
30
  assert_equal 1120.0, metric.value
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statsd-instrument
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0beta2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Storimer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-21 00:00:00.000000000 Z
12
+ date: 2014-04-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -104,9 +104,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
104
104
  version: '0'
105
105
  required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  requirements:
107
- - - '>'
107
+ - - '>='
108
108
  - !ruby/object:Gem::Version
109
- version: 1.3.1
109
+ version: '0'
110
110
  requirements: []
111
111
  rubyforge_project:
112
112
  rubygems_version: 2.0.3
@@ -124,4 +124,3 @@ test_files:
124
124
  - test/statsd_test.rb
125
125
  - test/test_helper.rb
126
126
  - test/udp_backend_test.rb
127
- has_rdoc: