Sha256: 169f363547696278652a1e647a8deea3caec695710793ce3830d726ccae15e12

Contents?: true

Size: 1.11 KB

Versions: 4

Compression:

Stored size: 1.11 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

4 entries across 4 versions & 1 rubygems

Version Path
lookout-rack-utils-3.0.1 lib/lookout/rack/utils/graphite.rb
lookout-rack-utils-3.0.0 lib/lookout/rack/utils/graphite.rb
lookout-rack-utils-2.0.0 lib/lookout/rack/utils/graphite.rb
lookout-rack-utils-1.7.3 lib/lookout/rack/utils/graphite.rb