Module: Watchman

Extended by:
Watchman
Included in:
Watchman
Defined in:
lib/watchman.rb,
lib/watchman/version.rb

Constant Summary collapse

VERSION =
"0.3.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hostObject

Returns the value of attribute host.



9
10
11
# File 'lib/watchman.rb', line 9

def host
  @host
end

#portObject

Returns the value of attribute port.



10
11
12
# File 'lib/watchman.rb', line 10

def port
  @port
end

#prefixObject

Returns the value of attribute prefix.



8
9
10
# File 'lib/watchman.rb', line 8

def prefix
  @prefix
end

Instance Method Details

#benchmark(name) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/watchman.rb', line 20

def benchmark(name)
  result = nil

  time = Benchmark.measure do
    result = yield
  end

  statsd_client.timing(metric_name_with_prefix(name), (time.real * 1000).floor)

  result
end

#metric_name_with_prefix(name) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/watchman.rb', line 32

def metric_name_with_prefix(name)
  if @prefix
    "#{@prefix}.#{name}"
  else
    name
  end
end

#statsd_clientObject



12
13
14
# File 'lib/watchman.rb', line 12

def statsd_client
  @client ||= Statsd.new(@host, @port)
end

#submit(name, value) ⇒ Object



16
17
18
# File 'lib/watchman.rb', line 16

def submit(name, value)
  statsd_client.gauge(metric_name_with_prefix(name), value)
end