hallmonitor 2.0.0 → 3.0.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 +9 -0
- data/lib/hallmonitor/outputters/influxdb.rb +33 -45
- data/lib/hallmonitor/version.rb +1 -1
- data/spec/hallmonitor/outputters/influxdb_spec.rb +18 -9
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 515e56a7cec5188387c88051f7ef6be3ab963b48
|
4
|
+
data.tar.gz: be30442a4e44804fbf679630fd4c67893907fa89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58e504bc5324180efb1af75aae1d73274b43b135fab2eff72788d7f296599454cb908b1c185ccd4560b535cd45aec5daee1fbb11582102b0f3ddc87a88ce33f6
|
7
|
+
data.tar.gz: 5bb63718cefb76199d649f4b066d05f67d63d738682758f2dc00c3d976d1a3ec4c640f850dd7cb2fd771849da329aadc5e96f1a53a70e4b5dd9169d22cad22e4
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# Version 3.0.0
|
2
|
+
- Refactored the Transformer concept in the InfluxDB outputter so that
|
3
|
+
it is more flexible. This was in response to the InfluxDB client gem
|
4
|
+
"fixing" a bug where numerical values were previously always sent as
|
5
|
+
floats, now numbers are marked as "integer" type if they are ruby
|
6
|
+
Integers which can lead to some field-type conflicts if you update
|
7
|
+
your InfluxDB gem version and were previously sending integers at
|
8
|
+
floats. Using the Transformer now allows you to modify the values
|
9
|
+
that will be sent to InfluxDB immediately before they're sent out.x
|
@@ -7,82 +7,70 @@ module Hallmonitor
|
|
7
7
|
module Outputters
|
8
8
|
# An outputter for InfluxDB
|
9
9
|
class Influxdb < Outputter
|
10
|
+
# Simple EventData struct, used to communicate with an optional Transformer
|
11
|
+
EventData = Struct.new(:name, :tags, :fields)
|
12
|
+
|
10
13
|
# Builds a new Influxdb outputter
|
11
14
|
# @param influxdb_client [InfluxDB::Client] client instance to use
|
12
15
|
# @param tags [Hash] Set of default tags applied to all events output to
|
13
16
|
# InfluxDB, will be overridden by tags set by events if they conflict
|
14
|
-
# @param transformer [#transform(
|
15
|
-
# to #transform(
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
# other words if the event has tags already they will take precedence
|
21
|
-
# over tags built by the transformer
|
17
|
+
# @param transformer [#transform(Event, EventData)] An object
|
18
|
+
# that responds to #transform(Event, EventData). If supplied
|
19
|
+
# it will be passed the {EventData} struct that has been built
|
20
|
+
# so far and it should return an {EventData} struct that will
|
21
|
+
# be written out to InfluxDB. This allows a hook to modify data
|
22
|
+
# before it is written out to InfluxDB
|
22
23
|
# @raise if influxdb_client does not respond to :write_point
|
23
24
|
# (InfluxDB::Client contract)
|
24
25
|
def initialize(influxdb_client, tags = {}, transformer = nil)
|
25
26
|
unless influxdb_client.respond_to?(:write_point)
|
26
|
-
|
27
|
+
raise 'Supplied InfluxDB Client was not as expected'
|
27
28
|
end
|
28
29
|
|
29
30
|
if transformer && !transformer.respond_to?(:transform)
|
30
|
-
|
31
|
+
raise 'Supplied transformer does not respond to :transform'
|
31
32
|
end
|
32
33
|
|
33
34
|
super('influxdb')
|
34
35
|
@tags = {}.merge(tags)
|
35
|
-
@client = influxdb_client ||
|
36
|
+
@client = influxdb_client || raise('Must supply an InfluxDb client')
|
36
37
|
@transformer = transformer
|
37
38
|
end
|
38
39
|
|
39
40
|
# Sends events to InfluxDB instance
|
40
|
-
# @param
|
41
|
+
# @param event [Hallmonitor::Event]
|
41
42
|
def process(event)
|
42
|
-
|
43
|
-
|
44
|
-
build_timer_data(event)
|
45
|
-
elsif event.is_a?(Hallmonitor::GaugeEvent)
|
46
|
-
build_gauge_data(event)
|
47
|
-
else
|
48
|
-
build_counter_data(event)
|
49
|
-
end
|
50
|
-
transform_and_write(event, data)
|
43
|
+
event_data = build_event_data(event)
|
44
|
+
transform_and_write(event, event_data)
|
51
45
|
end
|
52
46
|
|
53
47
|
private
|
54
48
|
|
55
|
-
|
56
|
-
|
57
|
-
|
49
|
+
# @param event [Event] The original event we're working with
|
50
|
+
# @param data [EventData] Struct of data we're building for InfluxDB
|
51
|
+
def transform_and_write(event, event_data)
|
52
|
+
event_data = @transformer.transform(event, event_data) if @transformer
|
53
|
+
data = { tags: event_data.tags, values: event_data.fields }
|
54
|
+
@client.write_point(event_data.name, data)
|
58
55
|
end
|
59
56
|
|
60
|
-
#
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
def transform(event, data)
|
67
|
-
if @transformer
|
68
|
-
t = @transformer.transform(event.name)
|
69
|
-
data[:tags] = (t[:tags] || {}).merge(data[:tags])
|
70
|
-
{ name: t[:name], data: data }
|
57
|
+
# Builds an {EventData} from the Hallmonitor::Event
|
58
|
+
def build_event_data(event)
|
59
|
+
if event.is_a?(Hallmonitor::TimedEvent)
|
60
|
+
build_timer_data(event)
|
61
|
+
elsif event.is_a?(Hallmonitor::GaugeEvent)
|
62
|
+
build_gauge_data(event)
|
71
63
|
else
|
72
|
-
|
64
|
+
build_counter_data(event)
|
73
65
|
end
|
74
66
|
end
|
75
67
|
|
68
|
+
# Builds an EventData struct for the event
|
76
69
|
def build_data(event, type, value)
|
77
|
-
data =
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
if value.is_a?(Hash)
|
82
|
-
data[:values] = value
|
83
|
-
else
|
84
|
-
data[:values] = { value: value }
|
85
|
-
end
|
70
|
+
data = EventData.new
|
71
|
+
data.name = event.name
|
72
|
+
data.tags = @tags.merge(event.tags.merge(type: type))
|
73
|
+
data.fields = value.is_a?(Hash) ? value : { value: value }
|
86
74
|
data
|
87
75
|
end
|
88
76
|
|
data/lib/hallmonitor/version.rb
CHANGED
@@ -11,7 +11,7 @@ module Hallmonitor
|
|
11
11
|
context '#initialize' do
|
12
12
|
context 'with a bad influxdb client' do
|
13
13
|
it 'raises an error' do
|
14
|
-
expect { outputter }.to raise_error
|
14
|
+
expect { outputter }.to raise_error
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -70,22 +70,31 @@ module Hallmonitor
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
context 'with a
|
74
|
-
let(:transformer) { double('
|
73
|
+
context 'with a transformer' do
|
74
|
+
let(:transformer) { double('transformer') }
|
75
75
|
let(:outputter) do
|
76
76
|
described_class.new(influxdb_client, default_tags, transformer)
|
77
77
|
end
|
78
78
|
|
79
|
+
let(:expected_data) do
|
80
|
+
{
|
81
|
+
values: { value: expected_value },
|
82
|
+
tags: { additional: 'foo' }
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
79
86
|
it 'builds event information using the transformer' do
|
80
87
|
expect(transformer).to(
|
81
88
|
receive(:transform)
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
89
|
+
.with(event, anything)
|
90
|
+
.and_return(
|
91
|
+
Influxdb::EventData.new(
|
92
|
+
'foo',
|
93
|
+
{ additional: 'foo' },
|
94
|
+
value: 1
|
95
|
+
)
|
96
|
+
)
|
87
97
|
)
|
88
|
-
expected_data[:tags][:additional] = 'foo'
|
89
98
|
expect(influxdb_client).to(
|
90
99
|
receive(:write_point).with('foo', expected_data))
|
91
100
|
outputter.process(event)
|
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
|
+
version: 3.0.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: 2016-
|
11
|
+
date: 2016-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -145,6 +145,7 @@ extra_rdoc_files: []
|
|
145
145
|
files:
|
146
146
|
- ".document"
|
147
147
|
- ".gitignore"
|
148
|
+
- CHANGELOG.md
|
148
149
|
- Gemfile
|
149
150
|
- LICENSE.txt
|
150
151
|
- README.md
|