Created
May 29, 2012 16:14
-
-
Save matsadler/2829290 to your computer and use it in GitHub Desktop.
EventMachine connectivity for the statsd-ruby client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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