Skip to content

Commit

Permalink
added FnordMetric::UDPClient
Browse files Browse the repository at this point in the history
  • Loading branch information
asmuth committed May 6, 2012
1 parent b20241d commit e0c0cbe
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/fnordmetric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def self.embedded(opts={})
end

require "fnordmetric/api"
require "fnordmetric/udp_client"
require "fnordmetric/inbound_stream"
require "fnordmetric/worker"
require "fnordmetric/widget"
Expand Down
22 changes: 22 additions & 0 deletions lib/fnordmetric/udp_client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class FnordMetric::UDPClient

def initialize(host, port)
@sock = UDPSocket.new
@sock.connect(host, port)
end

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

end

0 comments on commit e0c0cbe

Please sign in to comment.