lib/fozzie/adapter/statsd.rb in fozzie-1.0.0 vs lib/fozzie/adapter/statsd.rb in fozzie-1.0.1
- old
+ new
@@ -1,6 +1,7 @@
require 'socket'
+require 'resolv'
module Fozzie
module Adapter
class Statsd
@@ -57,11 +58,11 @@
# Send data to the server via the socket
def send_to_socket(message)
Fozzie.logger.debug {"Statsd: #{message}"} if Fozzie.logger
Timeout.timeout(Fozzie.c.timeout) {
- res = socket.send(message, 0, Fozzie.c.host, Fozzie.c.port)
+ res = socket.send(message, 0, host_ip, host_port)
Fozzie.logger.debug {"Statsd sent: #{res}"} if Fozzie.logger
(res.to_i == message.length)
}
rescue => exc
Fozzie.logger.debug {"Statsd Failure: #{exc.message}\n#{exc.backtrace}"} if Fozzie.logger
@@ -69,9 +70,17 @@
end
# The Socket we want to use to send data
def socket
@socket ||= ::UDPSocket.new
+ end
+
+ def host_ip
+ @host_ip ||= Resolv.getaddress(Fozzie.c.host)
+ end
+
+ def host_port
+ @host_port ||= Fozzie.c.port
end
def delimeter
DELIMETER
end