Class: Watchman

Inherits:
Object
  • Object
show all
Defined in:
lib/watchman.rb,
lib/watchman/version.rb,
lib/watchman/mock_statsd.rb

Defined Under Namespace

Classes: MockStatsd, SubmitTypeError

Constant Summary collapse

VERSION =
"0.7.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.hostObject

Returns the value of attribute host.



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

def host
  @host
end

.portObject

Returns the value of attribute port.



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

def port
  @port
end

.prefixObject

Returns the value of attribute prefix.



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

def prefix
  @prefix
end

.test_modeObject

Returns the value of attribute test_mode.



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

def test_mode
  @test_mode
end

Class Method Details

.benchmark(name) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/watchman.rb', line 26

def benchmark(name)
  result = nil

  time = Benchmark.measure do
    result = yield
  end

  submit(name, (time.real * 1000).floor, :timing)

  result
end

.decrement(name) ⇒ Object



42
43
44
# File 'lib/watchman.rb', line 42

def decrement(name)
  submit(name, -1, :count)
end

.increment(name) ⇒ Object



38
39
40
# File 'lib/watchman.rb', line 38

def increment(name)
  submit(name, 1, :count)
end

.submit(name, value, type = :gauge) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/watchman.rb', line 15

def submit(name, value, type = :gauge)
  metric = metric_name_with_prefix(name)

  case type
  when :gauge  then statsd_client.gauge(metric, value)
  when :timing then statsd_client.timing(metric, value)
  when :count  then statsd_client.count(metric, value)
  else raise SubmitTypeError.new("Submit type '#{type}' is not recognized")
  end
end