Class: Statue::UDPBackend

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host:, port:) ⇒ UDPBackend

Returns a new instance of UDPBackend.



12
13
14
15
# File 'lib/statue/backends/udp.rb', line 12

def initialize(host:, port:)
  @host = host
  @port = port
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



5
6
7
# File 'lib/statue/backends/udp.rb', line 5

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



5
6
7
# File 'lib/statue/backends/udp.rb', line 5

def port
  @port
end

Class Method Details

.from_uri(uri) ⇒ Object



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

def self.from_uri(uri)
  uri = URI(uri)
  new(host: uri.host, port: uri.port)
end

Instance Method Details

#collect_metric(metric) ⇒ Object Also known as: <<



17
18
19
20
21
# 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