Module: Statue
- Extended by:
- Statue
- Included in:
- Statue
- Defined in:
- lib/statue.rb,
lib/statue/clock.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,
lib/statue/sidekiq_statistics.rb
Defined Under Namespace
Modules: Clock, SidekiqStatistics
Classes: CaptureBackend, LoggerBackend, Metric, NullBackend, RackStatistics, Stopwatch, UDPBackend
Constant Summary
collapse
- VERSION =
'0.4.1'
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#debug(text, &block) ⇒ 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
46
47
48
|
# File 'lib/statue.rb', line 46
def backend
@backend ||= UDPBackend.from_uri("statsd://127.0.0.1:8125")
end
|
#logger ⇒ Object
Returns the value of attribute logger.
11
12
13
|
# File 'lib/statue.rb', line 11
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
50
51
52
|
# File 'lib/statue.rb', line 50
def debug(text, &block)
logger.debug(text, &block) if logger
end
|
#error(text, &block) ⇒ Object
54
55
56
|
# File 'lib/statue.rb', line 54
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
|
# 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
report_increment("#{metric_name}.#{success ? "success" : "failure"}", **options)
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
|