Class: Statsby::UDPMetricsWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/statsby/udp_metrics_writer.rb

Overview

Most StatsD endpoints will be UDP. This is a super simple wrapper around UPDSocket

Constant Summary collapse

DEFAULT_HOST =
'localhost'.freeze
DEFAULT_PORT =
8125

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host = DEFAULT_HOST, port = DEFAULT_PORT) ⇒ UDPMetricsWriter

Returns a new instance of UDPMetricsWriter.



12
13
14
15
16
# File 'lib/statsby/udp_metrics_writer.rb', line 12

def initialize(host = DEFAULT_HOST, port = DEFAULT_PORT)
  self.socket = ::UDPSocket.new
  self.host = host
  self.port = port
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



10
11
12
# File 'lib/statsby/udp_metrics_writer.rb', line 10

def host
  @host
end

#portObject

Returns the value of attribute port.



10
11
12
# File 'lib/statsby/udp_metrics_writer.rb', line 10

def port
  @port
end

#socketObject

Returns the value of attribute socket.



10
11
12
# File 'lib/statsby/udp_metrics_writer.rb', line 10

def socket
  @socket
end

Instance Method Details

#write(message) ⇒ Object



18
19
20
# File 'lib/statsby/udp_metrics_writer.rb', line 18

def write(message)
  socket.send(message, 0, host, port)
end