riemann-client 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/riemann/event.rb +24 -11
- data/lib/riemann/version.rb +1 -1
- metadata +1 -2
- data/lib/riemann/repl-port +0 -1
data/lib/riemann/event.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module Riemann
|
2
2
|
class Event
|
3
|
+
require 'set'
|
3
4
|
include Beefcake::Message
|
4
5
|
|
5
6
|
optional :time, :int64, 1
|
@@ -15,6 +16,17 @@ module Riemann
|
|
15
16
|
optional :metric_d, :double, 14
|
16
17
|
optional :metric_f, :float, 15
|
17
18
|
|
19
|
+
# Fields which don't really exist in protobufs, but which are reserved
|
20
|
+
# and can't be used as attributes.
|
21
|
+
VIRTUAL_FIELDS = Set.new([:metric])
|
22
|
+
# Fields which are specially encoded in the Event protobuf--that is, they
|
23
|
+
# can't be used as attributes.
|
24
|
+
RESERVED_FIELDS = fields.map do |i, field|
|
25
|
+
field.name.to_sym
|
26
|
+
end.reduce(VIRTUAL_FIELDS) do |set, field|
|
27
|
+
set << field
|
28
|
+
end
|
29
|
+
|
18
30
|
# Average a set of states together. Chooses the mean metric, the mode
|
19
31
|
# state, mode service, and the mean time. If init is provided, its values
|
20
32
|
# override (where present) the computed ones.
|
@@ -162,10 +174,14 @@ module Riemann
|
|
162
174
|
super hash
|
163
175
|
end
|
164
176
|
|
165
|
-
# Add extra attributes to the event as Attribute instances with values
|
166
|
-
|
167
|
-
self.attributes =
|
168
|
-
|
177
|
+
# Add extra attributes to the event as Attribute instances with values
|
178
|
+
# converted to String
|
179
|
+
self.attributes = hash.map do |key, value|
|
180
|
+
unless RESERVED_FIELDS.include? key.to_sym
|
181
|
+
Attribute.new(:key => key.to_s,
|
182
|
+
:value => (hash[key] || hash[key.to_sym]).to_s)
|
183
|
+
end
|
184
|
+
end.compact
|
169
185
|
else
|
170
186
|
super()
|
171
187
|
end
|
@@ -192,20 +208,19 @@ module Riemann
|
|
192
208
|
|
193
209
|
# Look up attributes
|
194
210
|
def [](k)
|
195
|
-
if
|
211
|
+
if RESERVED_FIELDS.include? k.to_sym
|
196
212
|
super
|
197
213
|
else
|
198
|
-
r = attributes.
|
199
|
-
r.size > 1 ? r : r.first
|
214
|
+
r = attributes.find {|a| a.key.to_s == k.to_s }.value
|
200
215
|
end
|
201
216
|
end
|
202
217
|
|
203
218
|
# Set attributes
|
204
219
|
def []=(k, v)
|
205
|
-
if
|
220
|
+
if RESERVED_FIELDS.include? k.to_sym
|
206
221
|
super
|
207
222
|
else
|
208
|
-
a = self.attributes.
|
223
|
+
a = self.attributes.find {|a| a.key == k.to_s }
|
209
224
|
if(a)
|
210
225
|
a.value = v.to_s
|
211
226
|
else
|
@@ -213,7 +228,5 @@ module Riemann
|
|
213
228
|
end
|
214
229
|
end
|
215
230
|
end
|
216
|
-
|
217
231
|
end
|
218
|
-
|
219
232
|
end
|
data/lib/riemann/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: riemann-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -75,7 +75,6 @@ files:
|
|
75
75
|
- lib/riemann/message.rb
|
76
76
|
- lib/riemann/metric_thread.rb
|
77
77
|
- lib/riemann/query.rb
|
78
|
-
- lib/riemann/repl-port
|
79
78
|
- lib/riemann/state.rb
|
80
79
|
- lib/riemann/version.rb
|
81
80
|
- LICENSE
|
data/lib/riemann/repl-port
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
56061
|