Sha256: a27666c82f03e804549538c699d3e0b871ce4785d2a608599c5ab8d967bf549f

Contents?: true

Size: 1 KB

Versions: 5

Compression:

Stored size: 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)
  #
  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)
    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

5 entries across 5 versions & 1 rubygems

Version Path
lookout-rack-utils-1.2.4 lib/lookout/rack/utils/graphite.rb
lookout-rack-utils-1.2.3 lib/lookout/rack/utils/graphite.rb
lookout-rack-utils-1.2.2 lib/lookout/rack/utils/graphite.rb
lookout-rack-utils-1.2.1 lib/lookout/rack/utils/graphite.rb
lookout-rack-utils-1.2.0 lib/lookout/rack/utils/graphite.rb