Class: Travis::Metrics

Inherits:
Object
  • 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.0'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reporter) ⇒ Metrics

Returns a new instance of Metrics.



33
34
35
# File 'lib/travis/metrics.rb', line 33

def initialize(reporter)
  @reporter = reporter
end

Instance Attribute Details

#reporterObject (readonly)

Returns the value of attribute reporter.



31
32
33
# File 'lib/travis/metrics.rb', line 31

def reporter
  @reporter
end

Class Method Details

.setup(config, logger) ⇒ Object



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

def setup(config, logger)
  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



22
23
24
25
26
27
28
# File 'lib/travis/metrics.rb', line 22

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) ⇒ Object



37
38
39
# File 'lib/travis/metrics.rb', line 37

def count(key)
  Metriks.counter(key).increment if reporter
end

#gauge(key, value) ⇒ Object



45
46
47
# File 'lib/travis/metrics.rb', line 45

def gauge(key, value)
  Metriks.gauge(key).set(value) if reporter
end

#meter(key) ⇒ Object



41
42
43
# File 'lib/travis/metrics.rb', line 41

def meter(key)
  Metriks.meter(key).mark if reporter
end

#time(key, &block) ⇒ Object



49
50
51
# File 'lib/travis/metrics.rb', line 49

def time(key, &block)
  reporter ? Metriks.timer(key).time(&block) : yield
end