Class: ActiveStatsD::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/active_statsd/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(host:, port:, namespace:) ⇒ Client

Returns a new instance of Client.



6
7
8
9
10
11
# File 'lib/active_statsd/client.rb', line 6

def initialize(host:, port:, namespace:)
  @host = host
  @port = port
  @namespace = namespace
  @socket = UDPSocket.new
end

Instance Method Details

#gauge(metric, value) ⇒ Object



17
18
19
# File 'lib/active_statsd/client.rb', line 17

def gauge(metric, value)
  send_metric("#{metric}:#{value}|g")
end

#increment(metric, by: 1) ⇒ Object



13
14
15
# File 'lib/active_statsd/client.rb', line 13

def increment(metric, by: 1)
  send_metric("#{metric}:#{by}|c")
end

#timing(metric) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/active_statsd/client.rb', line 21

def timing(metric)
  start_time = Time.now
  yield
ensure
  duration = ((Time.now - start_time) * 1000).round
  send_metric("#{metric}:#{duration}|ms")
end