Class: Meter::Backends::Udp

Inherits:
Base
  • Object
show all
Defined in:
lib/meter/backends/udp.rb

Direct Known Subclasses

Statsd

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#convert_to_backend_format, #emit_metric, #supported_metric?, supported_metrics

Constructor Details

#initialize(host: '127.0.0.1', port: 8125) ⇒ Udp

Returns a new instance of Udp.



10
11
12
# File 'lib/meter/backends/udp.rb', line 10

def initialize(host: '127.0.0.1', port: 8125)
  @host, @port = host, port
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



8
9
10
# File 'lib/meter/backends/udp.rb', line 8

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



8
9
10
# File 'lib/meter/backends/udp.rb', line 8

def port
  @port
end

Instance Method Details

#output_data(data) ⇒ Object



14
15
16
# File 'lib/meter/backends/udp.rb', line 14

def output_data(data)
  socket.send data, 0, self.host, self.port
end

#socketObject



18
19
20
# File 'lib/meter/backends/udp.rb', line 18

def socket
  Thread.current["meter_socket_#{self.class.name}"] ||= UDPSocket.new
end