Class: Lookout::Rack::Utils::Graphite

Inherits:
Object
  • Object
show all
Defined in:
lib/lookout/rack/utils/graphite.rb

Overview

Statsd proxy. This class initializes the Statsd client and delegates all stats related calls to it. It uses Lookout’s statsd (github.com/lookout/statsd) as a wrapper, which can be setup to use another implementation under the hood. Call Lookout::Statsd.set_instance BEFORE referencing the instance here in order to use a different Statsd implementation.

Use as:

Lookout::Rack::Utils::Graphite.increment('device.associated')
Lookout::Rack::Utils::Graphite.update_counter('device.associated', 5)
Lookout::Rack::Utils::Graphite.timing('device.associated', 3305)
Lookout::Rack::Utils::Graphite.time('device.associated') do
  # work
end

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGraphite

Private Constructor – treat this class like the Singleton it used to be



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/lookout/rack/utils/graphite.rb', line 25

def initialize
  if !Lookout::Statsd.instance_set?
    prefix = configatron.statsd.prefix
    unless ENV['RACK_ENV'] == 'production'
      prefix = "dev.#{ENV['USER']}.#{prefix}"
    end

    Lookout::Statsd.create_instance(:host => configatron.statsd.host,
                                    :port => configatron.statsd.port,
                                    :prefix => prefix)
  end
end

Class Method Details

.clear_instanceObject

Clear instance, for use in testing only



44
45
46
# File 'lib/lookout/rack/utils/graphite.rb', line 44

def self.clear_instance
  @instance = nil
end

.instanceObject

Provide same interface as old Singleton, but in test-friendly manner



39
40
41
# File 'lib/lookout/rack/utils/graphite.rb', line 39

def self.instance
  @instance ||= new
end

.method_missing(meth, *args, &block) ⇒ Object



48
49
50
# File 'lib/lookout/rack/utils/graphite.rb', line 48

def self.method_missing(meth, *args, &block)
  self.instance && Lookout::Statsd.instance.send(meth, *args, &block)
end

.respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/lookout/rack/utils/graphite.rb', line 52

def self.respond_to?(method, include_private = false)
  super || (self.instance && Lookout::Statsd.instance.respond_to?(method, include_private))
end