Class: FnordMetric::UDPClient
- Inherits:
-
Object
- Object
- FnordMetric::UDPClient
- Defined in:
- lib/fnordmetric/udp_client.rb
Instance Method Summary collapse
- #event(event_data) ⇒ Object
-
#initialize(host, port) ⇒ UDPClient
constructor
A new instance of UDPClient.
Constructor Details
#initialize(host, port) ⇒ UDPClient
Returns a new instance of UDPClient.
3 4 5 6 |
# File 'lib/fnordmetric/udp_client.rb', line 3 def initialize(host, port) @sock = UDPSocket.new @sock.connect(host, port) end |
Instance Method Details
#event(event_data) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# 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 |