hallmonitor 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a94b8069a987ca9eb3493b18f47b5a92b45b3881
4
- data.tar.gz: 44949242eb518251bb8327350c01f4001d978fb1
3
+ metadata.gz: 1079939216599f5d80202ba8bc96224365fbef78
4
+ data.tar.gz: 4fea628bc6f7faff08a44e71353ed8a4b6cdef17
5
5
  SHA512:
6
- metadata.gz: 30c54a353d079bfffc7285d229a9b4224ebcf9378fe91412c8e83a5ce4dab7d617d5bc12499890644842be9d5e9864e7f75debaf2ccc74a9b6475e52021163aa
7
- data.tar.gz: d17fbde9caa08887b1a704fe9ffa076f362e494b402afc599dee8e798c6f90783b7eef013268218144d08d291fe228d10a0b79795309de3f8ddc11fc52fe20bb
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"])
@@ -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
 
@@ -1,7 +1,7 @@
1
1
  module Hallmonitor
2
2
  module Version
3
3
  MAJOR = 1
4
- MINOR = 0
4
+ MINOR = 1
5
5
  PATCH = 0
6
6
  BUILD = nil
7
7
 
@@ -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.0.0
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-03-21 00:00:00.000000000 Z
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