hallmonitor 1.0.0 → 1.1.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 +4 -4
- data/hallmonitor.gemspec +1 -0
- data/lib/hallmonitor/event.rb +5 -3
- data/lib/hallmonitor/monitored.rb +4 -4
- data/lib/hallmonitor/outputters/influxdb.rb +54 -0
- data/lib/hallmonitor/timed_event.rb +2 -2
- data/lib/hallmonitor/version.rb +1 -1
- data/spec/hallmonitor/monitored_spec.rb +28 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1079939216599f5d80202ba8bc96224365fbef78
|
4
|
+
data.tar.gz: 4fea628bc6f7faff08a44e71353ed8a4b6cdef17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85a0f7f5276194396bc7b6c89d095661f676c4a511b61145b88a9129fa19fbfac3ebcfcfe447691555c43828a0410fc1933968f5110c60bfb6390bfcc786f567
|
7
|
+
data.tar.gz: dc97db0cf695876cc8aa50bb578bac2f2be58218c5fa7d349dc9eea46fbfed8dad7f3a659f5c2b9a06e50d69939359df9d63d97a83236e1e1e022b94dbcedf49
|
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("influxdb", ["~> 0.2.2"])
|
23
24
|
s.add_development_dependency("rspec", [">= 3.0"])
|
24
25
|
s.add_development_dependency("rdoc", [">= 0"])
|
25
26
|
s.add_development_dependency("bundler", ["~> 1.3"])
|
data/lib/hallmonitor/event.rb
CHANGED
@@ -5,22 +5,24 @@ module Hallmonitor
|
|
5
5
|
class Event
|
6
6
|
include Hallmonitor::Monitored
|
7
7
|
|
8
|
-
attr_accessor :name, :time, :count
|
8
|
+
attr_accessor :name, :time, :count, :tags
|
9
9
|
|
10
10
|
# Builds a new event
|
11
11
|
# @param name [String] the name of this event
|
12
12
|
# @param count [Number] the count of this even, defaults to 1
|
13
|
-
def initialize(name, count=1)
|
13
|
+
def initialize(name, count=1, tags: {})
|
14
14
|
@name = name
|
15
15
|
@time = Time.now
|
16
16
|
@count = count
|
17
|
+
@tags = tags
|
17
18
|
end
|
18
19
|
|
19
20
|
def to_json(*a)
|
20
21
|
{
|
21
22
|
name: @name,
|
22
23
|
time: @time,
|
23
|
-
count: @count
|
24
|
+
count: @count,
|
25
|
+
tags: @tags
|
24
26
|
}.to_json(*a)
|
25
27
|
end
|
26
28
|
end
|
@@ -62,10 +62,10 @@ module Hallmonitor
|
|
62
62
|
# @param event [Mixed] The thing to emit, see method description
|
63
63
|
# @yield [to_emit] The thing that's going to be emitted
|
64
64
|
# @return nil
|
65
|
-
def emit(event = nil)
|
65
|
+
def emit(event = nil, tags: {})
|
66
66
|
to_emit = self
|
67
67
|
unless event.nil?
|
68
|
-
to_emit = event.is_a?(Hallmonitor::Event) ? event : Hallmonitor::Event.new(event)
|
68
|
+
to_emit = event.is_a?(Hallmonitor::Event) ? event : Hallmonitor::Event.new(event, tags: tags)
|
69
69
|
end
|
70
70
|
|
71
71
|
# If we were given a block, then we want to execute that
|
@@ -80,8 +80,8 @@ module Hallmonitor
|
|
80
80
|
# @param name [String] The name of the event to emit
|
81
81
|
# @yield [event] the event object that will be emitted
|
82
82
|
# @return Whatever the block's return value is
|
83
|
-
def watch(name)
|
84
|
-
event = Hallmonitor::TimedEvent.new(name)
|
83
|
+
def watch(name, tags: {})
|
84
|
+
event = Hallmonitor::TimedEvent.new(name, tags: tags)
|
85
85
|
event.start = Time.now
|
86
86
|
begin
|
87
87
|
yield(event)
|
@@ -0,0 +1,54 @@
|
|
1
|
+
begin
|
2
|
+
require 'influxdb'
|
3
|
+
rescue LoadError
|
4
|
+
end
|
5
|
+
|
6
|
+
module Hallmonitor
|
7
|
+
module Outputters
|
8
|
+
# An outputter for StatsD
|
9
|
+
class InfluxdbOutputter < Outputter
|
10
|
+
# Builds a new InfluxdbOutputter
|
11
|
+
# @param influxdb_client [InfluxDB::Client] client instance to use
|
12
|
+
# @param tags [Hash] Set of default tags applied to all events output to
|
13
|
+
# InfluxDB, will be overridden by tags set by events if they conflict
|
14
|
+
# @raise if Statsd is undefined (Gem not present)
|
15
|
+
def initialize(influxdb_client, tags)
|
16
|
+
raise "In order to use InfluxdbOutputter, influxdb gem must be installed" unless defined?(InfluxDB)
|
17
|
+
super("influxdb")
|
18
|
+
@tags = tags
|
19
|
+
@client = influxdb_client
|
20
|
+
end
|
21
|
+
|
22
|
+
# Sends events to statsd instance
|
23
|
+
def process(event)
|
24
|
+
tags = @tags.merge(event.tags)
|
25
|
+
|
26
|
+
data = {}
|
27
|
+
|
28
|
+
if(event.respond_to?(:duration))
|
29
|
+
tags = {type: 'timer'}.merge(tags)
|
30
|
+
data = {
|
31
|
+
values: {value: event.duration},
|
32
|
+
tags: tags
|
33
|
+
}
|
34
|
+
@client.write_point(event.name, data)
|
35
|
+
elsif(event.respond_to?(:value))
|
36
|
+
tags = {type: 'guage'}.merge(tags)
|
37
|
+
data = {
|
38
|
+
values: {value: event.value},
|
39
|
+
tags: tags
|
40
|
+
}
|
41
|
+
else
|
42
|
+
tags = {type: 'count'}.merge(tags)
|
43
|
+
data = {
|
44
|
+
values: {value: event.count},
|
45
|
+
tags: tags
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
@client.write_point(event.name, data)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -11,8 +11,8 @@ module Hallmonitor
|
|
11
11
|
# Builds a new {TimedEvent}
|
12
12
|
# @param name [String] name of this event
|
13
13
|
# @param duration [Number] the timespan of this event
|
14
|
-
def initialize(name, duration=nil)
|
15
|
-
super(name)
|
14
|
+
def initialize(name, duration=nil, tags: {})
|
15
|
+
super(name, tags: tags)
|
16
16
|
@duration = duration
|
17
17
|
end
|
18
18
|
|
data/lib/hallmonitor/version.rb
CHANGED
@@ -18,6 +18,10 @@ RSpec::Matchers.define :an_event_with_name do |expected_name|
|
|
18
18
|
match { |actual| actual.is_a?(Hallmonitor::Event) && actual.name == expected_name }
|
19
19
|
end
|
20
20
|
|
21
|
+
RSpec::Matchers.define :an_event_with_tags do |expected_tags|
|
22
|
+
match { |actual| actual.is_a?(Hallmonitor::Event) && actual.tags == expected_tags}
|
23
|
+
end
|
24
|
+
|
21
25
|
RSpec::Matchers.define :a_timed_event_with_name do |expected_name|
|
22
26
|
match { |actual| actual.is_a?(Hallmonitor::TimedEvent) && actual.name == expected_name }
|
23
27
|
end
|
@@ -65,6 +69,19 @@ RSpec.describe Hallmonitor::Monitored do
|
|
65
69
|
end
|
66
70
|
end
|
67
71
|
|
72
|
+
describe 'with tags' do
|
73
|
+
let(:name) { 'foo'}
|
74
|
+
let(:tags) { {'foo': 'bar', 'baz': 6}}
|
75
|
+
|
76
|
+
it 'emits an event with tags' do
|
77
|
+
expect(Hallmonitor::Dispatcher).to(
|
78
|
+
receive(:output).with(an_event_with_tags(tags)))
|
79
|
+
subject.watch(name, tags: tags) do
|
80
|
+
'foo'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
68
85
|
describe 'when the block raises an error' do
|
69
86
|
it 'emits a timer for the block' do
|
70
87
|
expect(Hallmonitor::Dispatcher).to(
|
@@ -89,6 +106,17 @@ RSpec.describe Hallmonitor::Monitored do
|
|
89
106
|
end
|
90
107
|
end
|
91
108
|
|
109
|
+
describe 'with tags' do
|
110
|
+
let(:name) { 'foo'}
|
111
|
+
let(:tags) { {'foo': 'bar', 'baz': 6}}
|
112
|
+
|
113
|
+
it 'emits an event with tags' do
|
114
|
+
expect(Hallmonitor::Dispatcher).to(
|
115
|
+
receive(:output).with(an_event_with_tags(tags)))
|
116
|
+
subject.emit(name, tags: tags)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
92
120
|
describe 'with a block' do
|
93
121
|
it 'yields to the block' do
|
94
122
|
yielded = false
|
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: 1.
|
4
|
+
version: 1.1.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: 2015-
|
11
|
+
date: 2015-08-24 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: influxdb
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.2.2
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.2.2
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -145,6 +159,7 @@ files:
|
|
145
159
|
- lib/hallmonitor/middleware.rb
|
146
160
|
- lib/hallmonitor/monitored.rb
|
147
161
|
- lib/hallmonitor/outputter.rb
|
162
|
+
- lib/hallmonitor/outputters/influxdb.rb
|
148
163
|
- lib/hallmonitor/outputters/iooutputter.rb
|
149
164
|
- lib/hallmonitor/outputters/new_relic.rb
|
150
165
|
- lib/hallmonitor/outputters/statsd_outputter.rb
|