Module: Librato::Rack::SourcePrefix::Extensions::Collector

Defined in:
lib/librato/rack/source_prefix/extensions/collector.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/librato/rack/source_prefix/extensions/collector.rb', line 5

def self.included(klass)
  # Explicitly removing methods that we intend to override. This is
  # necessary so that the methods in our module will be used when
  # they're mixed-in to the real Collector class. Typically you wouldn't
  # do this, but since the methods we're overriding are just delegates
  # to other objects, we can safely remove the methods and call the
  # underlying objects directly from our new implementations.
  [:increment, :measure, :timing].each do |method|
    if klass.instance_methods(false).include?(method)
      klass.send(:remove_method, method)
    end
  end
end

Instance Method Details

#increment(counter, options = {}) ⇒ Object


19
20
21
22
23
24
25
# File 'lib/librato/rack/source_prefix/extensions/collector.rb', line 19

def increment(counter, options={})
  if prefix_needed?(options)
    options[:source] = apply_prefix(options[:source])
  end

  counters.increment(counter, options)
end

#measure(*args, &block) ⇒ Object Also known as: timing


27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/librato/rack/source_prefix/extensions/collector.rb', line 27

def measure(*args, &block)
  # If there are options
  if args.length > 1 and args[-1].respond_to?(:each)
    options = args[-1]

    if prefix_needed?(options)
      options[:source] = apply_prefix(options[:source])
    end
  end

  aggregate.measure(*args, &block)
end