Module: Statue

Extended by:
Statue
Included in:
Statue
Defined in:
lib/statue.rb,
lib/statue/metric.rb,
lib/statue/version.rb,
lib/statue/backends.rb,
lib/statue/stopwatch.rb,
lib/statue/backends/udp.rb,
lib/statue/backends/null.rb,
lib/statue/backends/logger.rb,
lib/statue/rack_statistics.rb,
lib/statue/backends/capture.rb

Defined Under Namespace

Classes: CaptureBackend, LoggerBackend, Metric, NullBackend, RackStatistics, Stopwatch, UDPBackend

Constant Summary collapse

VERSION =
'0.2.2'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#backendObject

Returns the value of attribute backend.



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

def backend
  @backend
end

#loggerObject

Returns the value of attribute logger.



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

def logger
  @logger
end

#namespaceObject

Returns the value of attribute namespace.



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

def namespace
  @namespace
end

Instance Method Details

#debug(text, &block) ⇒ Object



56
57
58
# File 'lib/statue.rb', line 56

def debug(text, &block)
  logger.debug(text, &block) if logger
end

#durationObject



50
51
52
53
54
# File 'lib/statue.rb', line 50

def duration
  start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  yield
  Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
end

#error(text, &block) ⇒ Object



60
61
62
# File 'lib/statue.rb', line 60

def error(text, &block)
  logger.error(text, &block) if logger
end

#report_duration(metric_name, duration = nil, **options, &block) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/statue.rb', line 14

def report_duration(metric_name, duration = nil, **options, &block)
  result = nil
  backend << Metric.measure(metric_name, duration: duration, **options) do
    result = block.call
  end
  result
end

#report_increment(metric_name, **options) ⇒ Object



22
23
24
# File 'lib/statue.rb', line 22

def report_increment(metric_name, **options)
  backend << Metric.counter(metric_name, **options)
end

#report_success_or_failure(metric_name, success_method: nil, **options, &block) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/statue.rb', line 26

def report_success_or_failure(metric_name, success_method: nil, **options, &block)
  result  = block.call
  success = success_method ? result.public_send(success_method) : result

  if success
    report_increment("#{metric_name}.success", **options)
  else
    report_increment("#{metric_name}.failure", **options)
  end

  result
rescue
  report_increment("#{metric_name}.failure", **options)
  raise
end

#stopwatch(metric_name) ⇒ Object



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

def stopwatch(metric_name)
  Stopwatch.new(name: metric_name, reporter: self)
end