class Statue::UDPBackend

Attributes

host[R]
port[R]

Public Class Methods

from_uri(uri) click to toggle source
# File lib/statue/backends/udp.rb, line 7
def self.from_uri(uri)
  uri = URI(uri)
  new(host: uri.host, port: uri.port)
end
new(host:, port:) click to toggle source
# File lib/statue/backends/udp.rb, line 12
def initialize(host:, port:)
  @host = host
  @port = port
end

Public Instance Methods

<<(metric)
Alias for: collect_metric
collect_metric(metric) click to toggle source
# File lib/statue/backends/udp.rb, line 17
def collect_metric(metric)
  if metric.sample_rate == 1 || rand < metric.sample_rate
    send_to_socket metric.to_s
  end
end
Also aliased as: <<

Private Instance Methods

send_to_socket(message) click to toggle source
# File lib/statue/backends/udp.rb, line 34
def send_to_socket(message)
  Statue.debug(message)
  socket.send(message, 0)
rescue => e
  Statue.error("#{e.class} #{e}")
  nil
end
socket() click to toggle source
# File lib/statue/backends/udp.rb, line 26
def socket
  Thread.current[:statue_socket] ||= begin
    socket = UDPSocket.new(Addrinfo.ip(host).afamily)
    socket.connect(host, port)
    socket
  end
end