class FnordMetric::UDPClient

Public Class Methods

new(host, port) click to toggle source
# File lib/fnordmetric/udp_client.rb, line 3
def initialize(host, port)
  @sock = UDPSocket.new
  @sock.connect(host, port)
end

Public Instance Methods

event(event_data) click to toggle source
# File lib/fnordmetric/udp_client.rb, line 8
def event(event_data)
  begin
    if event_data.is_a?(Hash)
      event_data = event_data.to_json
    else
      JSON.parse(event_data) # void ;)
    end
  rescue JSON::ParserError
    FnordMetric.log("event_lost: can't parse json")
  else
    @sock.send(event_data, 0)
  end
end