Class: Travis::Metrics
- Inherits:
-
Object
show all
- Defined in:
- lib/travis/metrics.rb,
lib/travis/metrics/sidekiq.rb,
lib/travis/metrics/version.rb,
lib/travis/metrics/reporter/librato.rb,
lib/travis/metrics/reporter/riemann.rb,
lib/travis/metrics/reporter/graphite.rb
Defined Under Namespace
Modules: Reporter
Classes: Sidekiq
Constant Summary
collapse
- MSGS =
{
no_reporter: 'No metrics reporter configured.',
error: '"Exception while starting metrics reporter: %s"'
}
- VERSION =
'2.0.1'
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(reporter) ⇒ Metrics
Returns a new instance of Metrics.
38
39
40
|
# File 'lib/travis/metrics.rb', line 38
def initialize(reporter)
@reporter = reporter
end
|
Instance Attribute Details
#reporter ⇒ Object
Returns the value of attribute reporter.
36
37
38
|
# File 'lib/travis/metrics.rb', line 36
def reporter
@reporter
end
|
Class Method Details
.setup(config, logger) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/travis/metrics.rb', line 14
def setup(config, logger)
unless Metriks.respond_to?(:enable_hdrhistogram)
raise 'Please ensure that you are using the travis-ci fork of the metriks gem at https://github.com/travis-ci/metriks'
end
Metriks.enable_hdrhistogram
reporter = start(config, logger)
logger.debug(MSGS[:no_reporter]) unless reporter
new(reporter)
rescue Exception => e
logger.error [e.message, e.backtrace].join("\n")
end
|
.start(config, logger) ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/travis/metrics.rb', line 27
def start(config, logger)
return unless adapter = config[:reporter]
config = config[adapter.to_sym] || {}
const = Reporter.const_get(adapter.capitalize) rescue nil
reporter = const && const.new(config, logger)
reporter.setup && reporter if reporter
end
|
Instance Method Details
#count(key, value = 1) ⇒ Object
42
43
44
|
# File 'lib/travis/metrics.rb', line 42
def count(key, value = 1)
Metriks.counter(key, value).increment
end
|
#gauge(key, value) ⇒ Object
50
51
52
|
# File 'lib/travis/metrics.rb', line 50
def gauge(key, value)
Metriks.gauge(key).set(value)
end
|
#meter(key, value = 1) ⇒ Object
46
47
48
|
# File 'lib/travis/metrics.rb', line 46
def meter(key, value = 1)
Metriks.meter(key).mark(value)
end
|
#time(key, &block) ⇒ Object
54
55
56
|
# File 'lib/travis/metrics.rb', line 54
def time(key, &block)
Metriks.timer(key).time(&block)
end
|