Sha256: 634100f7e346fe31e32bde4942e70d894052cef937ca1e96c768b12861b9b1aa

Contents?: true

Size: 1.1 KB

Versions: 6

Compression:

Stored size: 1.1 KB

Contents

require 'singleton'
require 'configatron'
require 'statsd'

module Lookout::Rack::Utils
  # Statsd proxy.  This class initializes the Statsd client and
  # delegates all stats related calls to it.
  #
  # 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') do
  #     # work
  #   end
  #
  class Graphite
    include Singleton

    def initialize
      prefix = configatron.statsd.prefix
      unless ENV['RACK_ENV'] == 'production'
        prefix = "dev.#{ENV['USER']}.#{prefix}"
      end

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

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

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
lookout-rack-utils-1.7.2 lib/lookout/rack/utils/graphite.rb
lookout-rack-utils-1.7.1 lib/lookout/rack/utils/graphite.rb
lookout-rack-utils-1.6.0 lib/lookout/rack/utils/graphite.rb
lookout-rack-utils-1.5.0 lib/lookout/rack/utils/graphite.rb
lookout-rack-utils-1.4.0 lib/lookout/rack/utils/graphite.rb
lookout-rack-utils-1.3.0 lib/lookout/rack/utils/graphite.rb