Module: Remnant::ClassMethods

Included in:
Remnant
Defined in:
lib/remnant/base.rb

Instance Method Summary collapse

Instance Method Details

#collectObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/remnant/base.rb', line 15

def collect
  @sample_counter ||= 0

  extra_remnant_key = Remnant::Discover.results.delete(:extra_remnant_key)

  if ::Rails.env.production? || ::Rails.env.staging? || ::Rails.env.demo?
    # only log if above sample rate
    if @sample_counter > configuration.sample_rate
      Remnant::Discover.results.map do |remnant_key, ms|
        key = [
               Remnant.configuration.tag,
               Remnant.configuration.env,
               extra_remnant_key,
               remnant_key
              ].compact.join('.')

        Remnant.handler.timing(key, ms.to_i)
      end

      @sample_counter = 0
    else
      @sample_counter += 1
    end
  else
    # always log in development mode
    Rails.logger.info "--------------Remnants Discovered--------------"

    Remnant::Discover.results.map do |remnant_key, ms|
      key = [
             extra_remnant_key,
             remnant_key
            ].compact.join('.')

      Rails.logger.info "#{ms.to_i}ms\t#{key}"
    end

    Rails.logger.info "-----------------------------------------------"
  end

  Remnant::Discover.results.clear
end

#configurationObject



7
8
9
# File 'lib/remnant/base.rb', line 7

def configuration
  @configuration ||= Remnant::Configuration.new.defaults!
end

#configure(&block) ⇒ Object



3
4
5
# File 'lib/remnant/base.rb', line 3

def configure(&block)
  configuration.instance_eval(&block)
end

#handlerObject



11
12
13
# File 'lib/remnant/base.rb', line 11

def handler
  @handler ||= Statsd.new(Remnant.configuration.hostname, Remnant.configuration.port_number)
end