module FFWD::Plugin::Protobuf::Serializer::Protocol0
Constants
- EVENT_FIELDS
- METRIC_FIELDS
- P
Public Class Methods
dump_event(event)
click to toggle source
# File lib/ffwd/plugin/protobuf/serializer/protocol0.rb, line 75 def self.dump_event event e = P::Event.new map_fields(EVENT_FIELDS, event) e.time = (event.time.to_f * 1000).to_i if event.time e.tags = to_tags event.tags if event.tags e.attributes = to_attributes event.attributes if event.attributes P::Message.new(:event => e).encode end
dump_metric(metric)
click to toggle source
# File lib/ffwd/plugin/protobuf/serializer/protocol0.rb, line 83 def self.dump_metric metric m = P::Metric.new map_fields(METRIC_FIELDS, metric) m.time = (metric.time.to_f * 1000).to_i if metric.time m.tags = to_tags metric.tags if metric.tags m.attributes = to_attributes metric.attributes if metric.attributes P::Message.new(:metric => m).encode end
from_attributes(source)
click to toggle source
# File lib/ffwd/plugin/protobuf/serializer/protocol0.rb, line 67 def self.from_attributes source Hash[source.map{|a| [a.key, a.value]}] end
load(string) { |:event, receive_event(event)| ... }
click to toggle source
# File lib/ffwd/plugin/protobuf/serializer/protocol0.rb, line 34 def self.load string message = P::Message.decode(string) if message.event yield :event, receive_event(message.event) end if message.metric yield :metric, receive_metric(message.metric) end end
map_fields(fields, s)
click to toggle source
# File lib/ffwd/plugin/protobuf/serializer/protocol0.rb, line 46 def self.map_fields fields, s Hash[fields.map{|f| [f, s.send(f)]}.reject{|f, v| v.nil?}] end
receive_event(event)
click to toggle source
# File lib/ffwd/plugin/protobuf/serializer/protocol0.rb, line 50 def self.receive_event event d = map_fields EVENT_FIELDS, event d[:time] = Time.at(event.time.to_f / 1000) if event.time d[:tags] = from_tags event.tags if event.tags d[:attributes] = from_attributes event.attributes if event.attributes return d end
receive_metric(metric)
click to toggle source
# File lib/ffwd/plugin/protobuf/serializer/protocol0.rb, line 58 def self.receive_metric metric d = map_fields METRIC_FIELDS, metric d[:proc] = metric.proc if metric.proc d[:time] = Time.at(metric.time.to_f / 1000) if metric.time d[:tags] = from_tags metric.tags if metric.tags d[:attributes] = from_attributes metric.attributes if metric.attributes return d end
Private Class Methods
to_attributes(attributes)
click to toggle source
# File lib/ffwd/plugin/protobuf/serializer/protocol0.rb, line 93 def self.to_attributes attributes attributes.map do |key, value| P::Attribute.new(:key => key.to_s, :value => value.to_s) end end