hallmonitor 4.1.0 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/hallmonitor.gemspec +1 -0
- data/lib/hallmonitor/gauge_event.rb +2 -2
- data/lib/hallmonitor/outputters/dogstatsd_outputter.rb +85 -0
- data/lib/hallmonitor/version.rb +1 -1
- data/spec/hallmonitor/outputters/dogstatsd_outputter_spec.rb +45 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d6589305a3290c2bf628e2a55f5ca6d13d4616b
|
4
|
+
data.tar.gz: 1e616bf4cb119aae142a64c4f70a6b043d5bf8a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3233ea964e32edbe665230f4f32e434b4988acacce629b12ae763d2313d7d5ef3a549e1f37af6685c3f4c8cf93f1870c33e7963925f70b11284869591f0518b2
|
7
|
+
data.tar.gz: 565ec6ba834afa8b0e81296a38df618c09ba759682d928b0ae69ec11301e6e8c7b3bd02f2800391b3c5be460f57288bc9eae3ecfd11920d9b0c2a15c3f01f515
|
data/CHANGELOG.md
CHANGED
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
|
3
|
-
# think of it like a tachometer or gas
|
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
|
data/lib/hallmonitor/version.rb
CHANGED
@@ -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.
|
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-
|
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
|