formatted-metrics 1.3.3 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/metrics.rb +1 -0
- data/lib/metrics/drivers/dog_statsd.rb +32 -0
- data/lib/metrics/instrumenter.rb +4 -0
- data/lib/metrics/version.rb +1 -1
- data/spec/metrics/drivers/dog_statsd_spec.rb +36 -0
- data/spec/metrics/instrumenter_spec.rb +13 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05827edaccbe8c352e7a7917205ab3847358414a
|
4
|
+
data.tar.gz: 8a8f41fcd65745cc921abfc86e2fe121997ef3a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 884c1f799016fbd47d7fb629d9bd024a3d255c992935413a3c817dc5f11d48e98a931cbe87a35a510584bb4b7d8d8abbac204b80684355fe7c0913211d86966d
|
7
|
+
data.tar.gz: 293a0d7b835fe274f9eec139f6b19c6db6a1a8aa3ac5ef32b6123c342fb16f2fdc1d10dc33db41425930738160c5710f12925f9b7e4ecfd3dfc096212a8c7222
|
data/lib/metrics.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
module Metrics::Drivers
|
2
|
+
class DogStatsd < Statsd
|
3
|
+
|
4
|
+
def emit(instrumenter)
|
5
|
+
name = name_for(instrumenter)
|
6
|
+
value = instrumenter.value
|
7
|
+
tags = formatted_tags(instrumenter.tags)
|
8
|
+
|
9
|
+
case instrumenter.type
|
10
|
+
when 'histogram'
|
11
|
+
client.histogram(name, value, tags: tags)
|
12
|
+
when 'measure', 'sample'
|
13
|
+
if instrumenter.units == 'ms'
|
14
|
+
client.timing(name, value, tags: tags)
|
15
|
+
else
|
16
|
+
client.gauge(name, value, tags: tags)
|
17
|
+
end
|
18
|
+
when 'count'
|
19
|
+
client.count(name, value, tags: tags)
|
20
|
+
else
|
21
|
+
raise ArgumentError.new("unsupported instrumenter type for dogstatsd: '%s'" % instrumenter.type)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def formatted_tags(tags)
|
28
|
+
tags.map { |k, v| "%s:%s" % [k, v.to_s.tr(' ', '_')] }
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
data/lib/metrics/instrumenter.rb
CHANGED
data/lib/metrics/version.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'securerandom'
|
3
|
+
|
4
|
+
describe Metrics::Drivers::DogStatsd do
|
5
|
+
let(:client) { double }
|
6
|
+
|
7
|
+
def instrumenter(*args)
|
8
|
+
Metrics::Instrumenter.new(*args)
|
9
|
+
end
|
10
|
+
|
11
|
+
def write(*instrumenters)
|
12
|
+
described_class.new(client, '{{name}}.source__{{source}}__', 'app').write(*instrumenters)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '.write' do
|
16
|
+
|
17
|
+
context 'tag support' do
|
18
|
+
|
19
|
+
it 'should pass an empty tag array if no tags are given' do
|
20
|
+
client.should_receive(:timing).with('rack.request.time.source__app__', 10.3333, tags: [])
|
21
|
+
write(instrumenter('rack.request.time', 10.3333, units: 'ms', type: 'sample'))
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should pass a tag to the dogstatsd-ruby client' do
|
25
|
+
client.should_receive(:gauge).with('rack.request.size.source__app__', 10, tags: ['tag0:long_value_with_lots_of_whitespace'])
|
26
|
+
write(instrumenter('rack.request.size', 10, type: 'measure', tags: {tag0: 'long value with lots of whitespace'}))
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should pass multiple tags to the dogstatsd-ruby client' do
|
30
|
+
client.should_receive(:count).with('foo.bar.source__app__', 10, tags: ['tag0:value0', 'tag1:a_tag_value', 'tag2:2222'])
|
31
|
+
write(instrumenter('foo.bar', 10, type: 'count', tags: {tag0: 'value0', tag1: :a_tag_value, tag2: 2222}))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -43,6 +43,19 @@ describe Metrics::Instrumenter do
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
+
describe '.tags' do
|
47
|
+
subject { instrumenter.tags }
|
48
|
+
|
49
|
+
context 'by default' do
|
50
|
+
it {should eq Hash.new }
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'when specified' do
|
54
|
+
let(:instrumenter) { described_class.new('jobs.busy', 10, units: 'jobs', tags: {tag0: 'value0', tag1: 'value1'}) }
|
55
|
+
it {should eq({tag0: 'value0', tag1: 'value1'})}
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
46
59
|
describe '.result' do
|
47
60
|
subject { instrumenter.result }
|
48
61
|
|
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.
|
4
|
+
version: 1.4.0
|
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: 2016-03-
|
11
|
+
date: 2016-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- lib/metrics.rb
|
87
87
|
- lib/metrics/configuration.rb
|
88
88
|
- lib/metrics/core_ext.rb
|
89
|
+
- lib/metrics/drivers/dog_statsd.rb
|
89
90
|
- lib/metrics/drivers/l2met.rb
|
90
91
|
- lib/metrics/drivers/statsd.rb
|
91
92
|
- lib/metrics/grouping.rb
|
@@ -99,6 +100,7 @@ files:
|
|
99
100
|
- lib/rack/instrumentation.rb
|
100
101
|
- lib/sidekiq/middleware/server/instrumentation.rb
|
101
102
|
- spec/faraday/instrumentation_spec.rb
|
103
|
+
- spec/metrics/drivers/dog_statsd_spec.rb
|
102
104
|
- spec/metrics/drivers/l2met_spec.rb
|
103
105
|
- spec/metrics/drivers/statsd_spec.rb
|
104
106
|
- spec/metrics/grouping_spec.rb
|
@@ -134,6 +136,7 @@ specification_version: 4
|
|
134
136
|
summary: Easily output formatted metrics to stdout
|
135
137
|
test_files:
|
136
138
|
- spec/faraday/instrumentation_spec.rb
|
139
|
+
- spec/metrics/drivers/dog_statsd_spec.rb
|
137
140
|
- spec/metrics/drivers/l2met_spec.rb
|
138
141
|
- spec/metrics/drivers/statsd_spec.rb
|
139
142
|
- spec/metrics/grouping_spec.rb
|