class StatfulAspects

Statful Aspects Instance

@attr_reader statful_client [Object] Statful client

Attributes

statful_client[R]

Public Class Methods

new(statful) click to toggle source

Initialize the client

@param [Object] statful Initialized Statful client @return [Object] The Statful aspects

# File lib/aspects.rb, line 17
def initialize(statful)
  raise ArgumentError.new('Statful client is missing') if statful.nil?

  @statful_client = statful
  self
end

Public Instance Methods

new() click to toggle source
# File lib/aspects.rb, line 9
def new
  self
end
timer(clazz, method, name, options = {}) click to toggle source

Sends a timer with the method execution time.

@param clazz [Object] Class to apply the aspect @param method [String] Name of the method to apply the aspect @param name [String] Name of the timer @param [Hash] options The options to apply to the metric @option options [Hash] :tags Tags to associate to the metric @option options [Array<String>] :agg List of aggregations to be applied by Statful @option options [Integer] :agg_freq Aggregation frequency in seconds @option options [String] :namespace Namespace of the metric

# File lib/aspects.rb, line 34
def timer(clazz, method, name, options = {})
  statful_client = @statful_client

  aspector(clazz, { :method => method }) do
    before do
      @before = Time.now
    end

    after do |result|
      now = Time.now
      time = (now - @before) * 1000.0
      statful_client.timer(name, time.round(3), options)
      result
    end
  end
end