hallmonitor 4.1.0 → 4.2.0

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: d535fc73fa9953de660b0884b36496a159c20d7b
4
- data.tar.gz: 336bb38e055f533a545d859eb92461b97f025438
3
+ metadata.gz: 4d6589305a3290c2bf628e2a55f5ca6d13d4616b
4
+ data.tar.gz: 1e616bf4cb119aae142a64c4f70a6b043d5bf8a4
5
5
  SHA512:
6
- metadata.gz: 8b637d698988d1f05b2603df29c94fc5fc7de6c8a845e331e8acc2599c093e675d9fc5b2d3214fd749c93eaedf00650cd94f99b941095a006f5413a0de6014ff
7
- data.tar.gz: 58add99e48674c87f883545c05b2a4b90301892b708086d1196c74cea358b4cf41498b9f212770ed2f66fd924f5ee8cec72d176443ed935b789540eb5ad8091e
6
+ metadata.gz: 3233ea964e32edbe665230f4f32e434b4988acacce629b12ae763d2313d7d5ef3a549e1f37af6685c3f4c8cf93f1870c33e7963925f70b11284869591f0518b2
7
+ data.tar.gz: 565ec6ba834afa8b0e81296a38df618c09ba759682d928b0ae69ec11301e6e8c7b3bd02f2800391b3c5be460f57288bc9eae3ecfd11920d9b0c2a15c3f01f515
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # Verison 4.2.0
2
+ - Added Dogstatsd outputter, thanks to mlahaye
3
+
1
4
  # Version 4.0.0
2
5
  - Changed initializer signature for InfluxDB outputter to use
3
6
  keyword args.
data/hallmonitor.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.add_runtime_dependency("json", [">= 0"])
21
21
 
22
22
  s.add_development_dependency("statsd-ruby", [">= 0"])
23
+ s.add_development_dependency("dogstatsd-ruby", [">= 0"])
23
24
  s.add_development_dependency("influxdb", ["~> 0.2.2"])
24
25
  s.add_development_dependency("rspec", [">= 3.0"])
25
26
  s.add_development_dependency("rdoc", [">= 0"])
@@ -1,6 +1,6 @@
1
1
  module Hallmonitor
2
- # A Guage event is an event that has a specific value,
3
- # think of it like a tachometer or gas guage on a car:
2
+ # A Gauge event is an event that has a specific value,
3
+ # think of it like a tachometer or gas gauge on a car:
4
4
  # at any given point it reports the current value of a
5
5
  # variable.
6
6
  class GaugeEvent < Event
@@ -0,0 +1,85 @@
1
+ begin
2
+ require 'datadog/statsd'
3
+ rescue LoadError
4
+ end
5
+
6
+ module Hallmonitor
7
+ module Outputters
8
+ # An outputter for Dogstatsd
9
+ class DogstatsdOutputter < Outputter
10
+ # Builds a new DogstatsdOutputter.
11
+ # @param prefix [String] Prefix for all events output by this outputter,
12
+ # the prefix will be applied to all event names before sending to statsd
13
+ # @param host [String] Datadog Host, defaults to '127.0.0.1'
14
+ # @param port [Number] Datadog Port, defaults to 8125
15
+ # @raise if Datadog::Statsd is undefined (Gem not present)
16
+ def initialize(prefix, host = '127.0.0.1', port = 8125, tags: {})
17
+ unless defined?(Datadog::Statsd)
18
+ fail 'In order to use DogstatsdOutputter, dogstatsd-ruby gem must be installed'
19
+ end
20
+
21
+ super(prefix)
22
+ @tags = {}.merge(tags)
23
+ @statsd = Datadog::Statsd.new(host).tap { |sd| sd.namespace = name }
24
+ end
25
+
26
+ # Sends events to statsd instance
27
+ # If the event's value field is a hash, this will send multiple events
28
+ # to statsd with the original name suffixed by the name of the events
29
+ # in the hash
30
+
31
+ def process_tags(tags)
32
+ @tags.merge(tags).map {|key, value| "#{key}:#{value}"}
33
+ end
34
+
35
+ def process(event)
36
+ if event.is_a?(Hallmonitor::TimedEvent)
37
+ process_timed_event(event)
38
+ elsif event.is_a?(Hallmonitor::GaugeEvent)
39
+ process_gauge_event(event)
40
+ else
41
+ process_event(event)
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def process_timed_event(event)
48
+ event_name = name_for(event)
49
+ if event.duration.is_a?(Hash)
50
+ event.duration.each do |name, value|
51
+ @statsd.timing("#{event_name}.#{name}", value, tags: process_tags(event.tags))
52
+ end
53
+ else
54
+ @statsd.timing(event_name, event.duration, tags: process_tags(event.tags))
55
+ end
56
+ end
57
+
58
+ def process_gauge_event(event)
59
+ event_name = name_for(event)
60
+ if event.value.is_a?(Hash)
61
+ event.value.each do |name, value|
62
+ @statsd.gauge("#{event_name}.#{name}", value, tags: process_tags(event.tags))
63
+ end
64
+ else
65
+ @statsd.gauge(event_name, event.value, tags: process_tags(event.tags))
66
+ end
67
+ end
68
+
69
+ def process_event(event)
70
+ event_name = name_for(event)
71
+ if event.count.is_a?(Hash)
72
+ event.count.each do |name, value|
73
+ @statsd.count("#{event_name}.#{name}", value, tags: process_tags(event.tags))
74
+ end
75
+ else
76
+ @statsd.count(event_name, event.count, tags: process_tags(event.tags))
77
+ end
78
+ end
79
+
80
+ def name_for(event)
81
+ event.name
82
+ end
83
+ end
84
+ end
85
+ end
@@ -1,7 +1,7 @@
1
1
  module Hallmonitor
2
2
  module Version
3
3
  MAJOR = 4
4
- MINOR = 1
4
+ MINOR = 2
5
5
  PATCH = 0
6
6
  BUILD = nil
7
7
 
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+ require 'hallmonitor/outputters/dogstatsd_outputter'
3
+
4
+ module Hallmonitor
5
+ module Outputters
6
+ RSpec.describe DogstatsdOutputter do
7
+ let(:dogstatsd_client) { instance_double(Datadog::Statsd) }
8
+ let(:prefix) { 'test' }
9
+ let(:outputter) { described_class.new(prefix) }
10
+
11
+ before do
12
+ allow(dogstatsd_client).to receive(:namespace=)
13
+ allow(Datadog::Statsd).to receive(:new).and_return(dogstatsd_client)
14
+ end
15
+
16
+ it 'can be instantiated' do
17
+ expect { outputter }.to_not raise_error
18
+ end
19
+
20
+ context '#process' do
21
+ let(:event_name) { 'foo.bar.baz' }
22
+ let(:event_tags) { {foo:"bar"} }
23
+ let(:event_tags_expected) {{tags:["foo:bar"]}}
24
+ context 'with an event' do
25
+ let(:event) { Event.new(name = event_name, tags: event_tags) }
26
+
27
+ it 'sends the event to statsd' do
28
+ expect(dogstatsd_client).to receive(:count).with(event_name, event.count, event_tags_expected)
29
+ outputter.process(event)
30
+ end
31
+
32
+ context 'that has multiple values' do
33
+ let(:values) { { foo: 1, bar: 2 } }
34
+ let(:event) { Event.new(event_name, count: values, tags: event_tags) }
35
+ it 'sends multiple events to statsd' do
36
+ expect(dogstatsd_client).to receive(:count).with("#{event_name}.foo", event.count[:foo], event_tags_expected)
37
+ expect(dogstatsd_client).to receive(:count).with("#{event_name}.bar", event.count[:bar], event_tags_expected)
38
+ outputter.process(event)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hallmonitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris TenHarmsel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-20 00:00:00.000000000 Z
11
+ date: 2017-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: dogstatsd-ruby
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: influxdb
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -160,6 +174,7 @@ files:
160
174
  - lib/hallmonitor/middleware.rb
161
175
  - lib/hallmonitor/monitored.rb
162
176
  - lib/hallmonitor/outputter.rb
177
+ - lib/hallmonitor/outputters/dogstatsd_outputter.rb
163
178
  - lib/hallmonitor/outputters/influxdb.rb
164
179
  - lib/hallmonitor/outputters/iooutputter.rb
165
180
  - lib/hallmonitor/outputters/new_relic.rb
@@ -168,6 +183,7 @@ files:
168
183
  - lib/hallmonitor/version.rb
169
184
  - spec/hallmonitor/dispatcher_spec.rb
170
185
  - spec/hallmonitor/monitored_spec.rb
186
+ - spec/hallmonitor/outputters/dogstatsd_outputter_spec.rb
171
187
  - spec/hallmonitor/outputters/influxdb_spec.rb
172
188
  - spec/hallmonitor/outputters/statsd_outputter_spec.rb
173
189
  - spec/spec_helper.rb
@@ -198,6 +214,7 @@ summary: Simple Ruby Event Monitoring
198
214
  test_files:
199
215
  - spec/hallmonitor/dispatcher_spec.rb
200
216
  - spec/hallmonitor/monitored_spec.rb
217
+ - spec/hallmonitor/outputters/dogstatsd_outputter_spec.rb
201
218
  - spec/hallmonitor/outputters/influxdb_spec.rb
202
219
  - spec/hallmonitor/outputters/statsd_outputter_spec.rb
203
220
  - spec/spec_helper.rb