Sha256: dd7ec5f33f6992e85fdce83acaad5215ca77e8df861c63b91eb36bfa0db79660

Contents?: true

Size: 1.14 KB

Versions: 6

Compression:

Stored size: 1.14 KB

Contents

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

require 'lookout/rack/utils'

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-3.3.0.24 lib/lookout/rack/utils/graphite.rb
lookout-rack-utils-3.3.0.22 lib/lookout/rack/utils/graphite.rb
lookout-rack-utils-3.2.0.19 lib/lookout/rack/utils/graphite.rb
lookout-rack-utils-3.2.0.16 lib/lookout/rack/utils/graphite.rb
lookout-rack-utils-3.1.0.12 lib/lookout/rack/utils/graphite.rb
lookout-rack-utils-3.0.1.11 lib/lookout/rack/utils/graphite.rb