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.8.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, args = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/watchman.rb', line 29

def benchmark(name, args = {})
  tags = args[:tags] || []

  result = nil

  time = Benchmark.measure do
    result = yield
  end

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

  result
end

.decrement(name, args = {}) ⇒ Object



49
50
51
52
53
# File 'lib/watchman.rb', line 49

def decrement(name, args = {})
  tags = args[:tags] || []

  submit(name, -1, type: :count, tags: tags)
end

.increment(name, args = {}) ⇒ Object



43
44
45
46
47
# File 'lib/watchman.rb', line 43

def increment(name, args = {})
  tags = args[:tags] || []

  submit(name, 1, type: :count, tags: tags)
end

.submit(name, value, args = {}) ⇒ Object



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

def submit(name, value, args = {})
  type = args[:type] || :gauge
  tags = args[:tags] || []

  metric = metric_name_with_prefix(name, tags)

  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