formatted-metrics 1.3.0 → 1.3.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f61de2711adaea249e6fc4f6eb53d9899ed805ef
4
- data.tar.gz: 5292dea3deae43f089de2eeb20d0512acbd3aebb
3
+ metadata.gz: 7d33ddd37a5151fefe56beb65c13bd3b9b503efd
4
+ data.tar.gz: 0c0eeaecbca51357625094b954838bd77eab512e
5
5
  SHA512:
6
- metadata.gz: 7c34b9936b1ae2ea1c6504e85432c9c0a7a63384cb063799e1be98f94702c652dec05d993c432152f47f9132d19fc6cc0cb86e945041dc1d4ecc2650d395a931
7
- data.tar.gz: 330e3349dbc4848df534f4a9d85bff0ca0a187897cda130500d9bf89f9dcf631cd595634a39c484ed0e46ac3dbe6869112af4ca7617fe78cf9909d2b830d7634
6
+ metadata.gz: 34abc4c6d556e752fdf55d975260d1892458ece7f17c1a3228b80c2a0c124ba69664bc3cba9bc11d4648d5b4f830871737df37f1ca92e9617abce8ddbff7923a
7
+ data.tar.gz: 6d921f8f040ff949c5b05334bddf7f149ec213b86f54d73b3d5fc43d130ca71861a8d0639612a878449e2cebb2c2f88db78d9c3e9ba45443599b675ef4cb9be0
@@ -37,9 +37,11 @@ module Metrics::Drivers
37
37
  end
38
38
 
39
39
  def measurement(instrumenter)
40
+ type = instrumenter.type
41
+ type = 'measure' if type == 'histogram' # histogram not supported.
40
42
  value = instrumenter.value
41
43
  value = value.round(PRECISION) if value.is_a?(Float)
42
- "#{instrumenter.type}##{instrumenter.metric}=#{value}#{instrumenter.units}"
44
+ "#{type}##{instrumenter.metric}=#{value}#{instrumenter.units}"
43
45
  end
44
46
 
45
47
  def blank?(string)
@@ -20,6 +20,8 @@ module Metrics::Drivers
20
20
  value = instrumenter.value
21
21
 
22
22
  case instrumenter.type
23
+ when 'histogram'
24
+ client.histogram(name, value)
23
25
  when 'measure', 'sample'
24
26
  if instrumenter.units == 'ms'
25
27
  client.timing(name, value)
@@ -2,6 +2,8 @@ module Metrics
2
2
  # Public: Starts a new Grouping context, which allows for multiple
3
3
  # instruments to output on a single line.
4
4
  class Grouping
5
+ include StatsdApi
6
+
5
7
  attr_reader :namespace, :instrumenters, :options
6
8
 
7
9
  def self.instrument(namespace = nil, options = {}, &block)
@@ -16,7 +18,7 @@ module Metrics
16
18
  end
17
19
 
18
20
  def increment(metric)
19
- instrument metric, 1, options.merge(type: 'count')
21
+ super(metric, options)
20
22
  end
21
23
 
22
24
  def instrument(metric, *args, &block)
@@ -0,0 +1,34 @@
1
+ module Metrics
2
+ # This adds a statsd compatible api that delegates back to #instrument
3
+ module StatsdApi
4
+ def increment(stat, options = {})
5
+ instrument stat, 1, options.merge(type: 'count')
6
+ end
7
+
8
+ def decrement(stat, options = {})
9
+ instrument stat, -1, options.merge(type: 'count')
10
+ end
11
+
12
+ def count(stat, count, options = {})
13
+ instrument stat, count, options.merge(type: 'count')
14
+ end
15
+
16
+ def gauge(stat, value, options = {})
17
+ instrument stat, value, options.merge(type: 'measure')
18
+ end
19
+
20
+ def histogram(stat, value, options = {})
21
+ instrument stat, value, options.merge(type: 'histogram')
22
+ end
23
+
24
+ def timing(stat, ms, options = {})
25
+ instrument stat, ms, options.merge(type: 'measure', units: 'ms')
26
+ end
27
+
28
+ def time(stat, options = {})
29
+ instrument stat, options do
30
+ yield
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,3 +1,3 @@
1
1
  module FormattedMetrics
2
- VERSION = '1.3.0'
2
+ VERSION = '1.3.1'
3
3
  end
data/lib/metrics.rb CHANGED
@@ -9,6 +9,7 @@ module Metrics
9
9
  autoload :Instrumenter, 'metrics/instrumenter'
10
10
  autoload :Grouping, 'metrics/grouping'
11
11
  autoload :Handler, 'metrics/handler'
12
+ autoload :StatsdApi, 'metrics/statsd_api'
12
13
 
13
14
  module Drivers
14
15
  autoload :Base, 'metrics/drivers/base'
@@ -27,6 +28,7 @@ module Metrics
27
28
  end
28
29
 
29
30
  class << self
31
+ include StatsdApi
30
32
 
31
33
  # Public: Instrument a metric.
32
34
  #
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ class StatsdApiTest
4
+ extend Metrics::StatsdApi
5
+ end
6
+
7
+ describe Metrics::StatsdApi do
8
+
9
+ describe '#increment' do
10
+ it 'delegates to instrument' do
11
+ StatsdApiTest.should_receive(:instrument).with('rack.request', 1, type: 'count')
12
+ StatsdApiTest.increment('rack.request')
13
+ end
14
+ end
15
+
16
+ describe '#decrement' do
17
+ it 'delegates to instrument' do
18
+ StatsdApiTest.should_receive(:instrument).with('rack.request', -1, type: 'count')
19
+ StatsdApiTest.decrement('rack.request')
20
+ end
21
+ end
22
+
23
+ describe '#count' do
24
+ it 'delegates to instrument' do
25
+ StatsdApiTest.should_receive(:instrument).with('rack.request', 10, type: 'count')
26
+ StatsdApiTest.count('rack.request', 10)
27
+ end
28
+ end
29
+
30
+ describe '#gauge' do
31
+ it 'delegates to instrument' do
32
+ StatsdApiTest.should_receive(:instrument).with('rack.request', 100, type: 'measure')
33
+ StatsdApiTest.gauge('rack.request', 100)
34
+ end
35
+ end
36
+
37
+ describe '#histogram' do
38
+ it 'delegates to instrument' do
39
+ StatsdApiTest.should_receive(:instrument).with('rack.request', 100, type: 'histogram')
40
+ StatsdApiTest.histogram('rack.request', 100)
41
+ end
42
+ end
43
+
44
+ describe '#timing' do
45
+ it 'delegates to instrument' do
46
+ StatsdApiTest.should_receive(:instrument).with('rack.request.latency', 1000, type: 'measure', units: 'ms')
47
+ StatsdApiTest.timing('rack.request.latency', 1000)
48
+ end
49
+ end
50
+
51
+ describe '#time' do
52
+ it 'delegates to instrument' do
53
+ StatsdApiTest.should_receive(:instrument).with('rack.request.latency', {}).and_yield
54
+ StatsdApiTest.time('rack.request.latency') { }
55
+ end
56
+ end
57
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formatted-metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric J. Holmes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-30 00:00:00.000000000 Z
11
+ date: 2015-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,7 @@ files:
94
94
  - lib/metrics/instrumenter.rb
95
95
  - lib/metrics/middleware_helpers.rb
96
96
  - lib/metrics/railtie.rb
97
+ - lib/metrics/statsd_api.rb
97
98
  - lib/metrics/version.rb
98
99
  - lib/rack/instrumentation.rb
99
100
  - lib/sidekiq/middleware/server/instrumentation.rb
@@ -103,6 +104,7 @@ files:
103
104
  - spec/metrics/grouping_spec.rb
104
105
  - spec/metrics/instrumentable_spec.rb
105
106
  - spec/metrics/instrumenter_spec.rb
107
+ - spec/metrics/statsd_api_spec.rb
106
108
  - spec/metrics_spec.rb
107
109
  - spec/rack/instrumentation_spec.rb
108
110
  - spec/spec_helper.rb
@@ -137,7 +139,7 @@ test_files:
137
139
  - spec/metrics/grouping_spec.rb
138
140
  - spec/metrics/instrumentable_spec.rb
139
141
  - spec/metrics/instrumenter_spec.rb
142
+ - spec/metrics/statsd_api_spec.rb
140
143
  - spec/metrics_spec.rb
141
144
  - spec/rack/instrumentation_spec.rb
142
145
  - spec/spec_helper.rb
143
- has_rdoc: