Skip to content

Instantly share code, notes, and snippets.

@matsadler
Created May 29, 2012 16:14
Show Gist options
  • Save matsadler/2829290 to your computer and use it in GitHub Desktop.
Save matsadler/2829290 to your computer and use it in GitHub Desktop.
EventMachine connectivity for the statsd-ruby client
require "eventmachine"
require "statsd" # statsd-ruby gem
module EventMachine
class Statsd < ::Statsd
class ConnectionWrapper
def initialize(em_connection)
@em_connection = em_connection
end
def send(message, flags, host, port)
@em_connection.send_datagram(message, host, port)
end
end
attr_reader :socket
private :socket
def initialize(host, port=8125)
super
# eventmachine forces us to listen on a UDP socket even though we only
# want to send, so we'll just give it a junk address
em_connection = EM.open_datagram_socket("0.0.0.0", 0, EM::Connection)
@socket = ConnectionWrapper.new(em_connection)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment