class FFWD::Plugin::JSON::Connection
Constants
- EVENT_FIELDS
- METRIC_FIELDS
Public Class Methods
new(bind, core, config)
click to toggle source
# File lib/ffwd/plugin/json/connection.rb, line 42 def initialize bind, core, config @bind = bind @core = core end
Public Instance Methods
read_event(data)
click to toggle source
# File lib/ffwd/plugin/json/connection.rb, line 98 def read_event data d = {} read_tags d, data read_time d, data EVENT_FIELDS.each do |from, to| next if (v = data[from]).nil? d[to] = v end d end
read_metric(data)
click to toggle source
# File lib/ffwd/plugin/json/connection.rb, line 84 def read_metric data d = {} read_tags d, data read_time d, data METRIC_FIELDS.each do |from, to| next if (v = data[from]).nil? d[to] = v end d end
read_time(d, source)
click to toggle source
# File lib/ffwd/plugin/json/connection.rb, line 79 def read_time d, source return if (time = source["time"]).nil? d[:time] = Time.at time end
receive_json(data)
click to toggle source
# File lib/ffwd/plugin/json/connection.rb, line 47 def receive_json data data = JSON.load(data) unless type = data["type"] raise "Field 'type' missing from received line" end if type == "metric" @core.input.metric read_metric(data) @bind.increment :received_metrics return end if type == "event" @core.input.event read_event(data) @bind.increment :received_events return end raise "No such type: #{type}" end