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.7'
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#debug(text, &block) ⇒ Object
-
#duration ⇒ Object
-
#error(text, &block) ⇒ Object
-
#report_duration(metric_name, duration = nil, **options, &block) ⇒ Object
-
#report_gauge(metric_name, value, **options) ⇒ Object
-
#report_increment(metric_name, value = 1, **options) ⇒ Object
-
#report_success_or_failure(metric_name, success_method: nil, **options, &block) ⇒ Object
-
#stopwatch(metric_name) ⇒ Object
Instance Attribute Details
#backend ⇒ Object
Returns the value of attribute backend.
12
13
14
|
# File 'lib/statue.rb', line 12
def backend
@backend
end
|
#logger ⇒ Object
Returns the value of attribute logger.
10
11
12
|
# File 'lib/statue.rb', line 10
def logger
@logger
end
|
#namespace ⇒ Object
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
60
61
62
|
# File 'lib/statue.rb', line 60
def debug(text, &block)
logger.debug(text, &block) if logger
end
|
#duration ⇒ Object
54
55
56
57
58
|
# File 'lib/statue.rb', line 54
def duration
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
yield
Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
end
|
#error(text, &block) ⇒ Object
64
65
66
|
# File 'lib/statue.rb', line 64
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_gauge(metric_name, value, **options) ⇒ Object
26
27
28
|
# File 'lib/statue.rb', line 26
def report_gauge(metric_name, value, **options)
backend << Metric.gauge(metric_name, value, **options)
end
|
#report_increment(metric_name, value = 1, **options) ⇒ Object
22
23
24
|
# File 'lib/statue.rb', line 22
def report_increment(metric_name, value = 1, **options)
backend << Metric.counter(metric_name, value, **options)
end
|
#report_success_or_failure(metric_name, success_method: nil, **options, &block) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/statue.rb', line 30
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
46
47
48
|
# File 'lib/statue.rb', line 46
def stopwatch(metric_name)
Stopwatch.new(name: metric_name, reporter: self)
end
|