Class: Statsdeify::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/statsdeify/writer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Writer

Returns a new instance of Writer.



5
6
7
# File 'lib/statsdeify/writer.rb', line 5

def initialize(url)
  self.url = url
end

Instance Attribute Details

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/statsdeify/writer.rb', line 3

def url
  @url
end

Instance Method Details

#puts(measurement) ⇒ Object



18
19
20
# File 'lib/statsdeify/writer.rb', line 18

def puts(measurement)
  socket.send(measurement.to_s, 0) 
end

#socketObject



9
10
11
12
13
14
15
16
# File 'lib/statsdeify/writer.rb', line 9

def socket
  unless @socket
    uri = URI.parse(url)
    @socket = UDPSocket.new
    @socket.connect(uri.host, uri.port)
  end
  @socket
end