module Statsn

Constants

PREFIX
VERSION

Attributes

api_key[RW]

Public Class Methods

increment(who, amount = 1) click to toggle source

Increments the count of the key by the given amount, default 1

# File lib/statsn.rb, line 11
def increment(who, amount = 1)
  stat(key(who)).record_data_point(amount)
end
time(who, &block) click to toggle source

Times the given block and returns the output of the block

# File lib/statsn.rb, line 16
def time(who, &block)
  trace_execution_unscoped(key(who), {}, &block)
end

Private Class Methods

key(who) click to toggle source
# File lib/statsn.rb, line 26
def key(who)
  if who.is_a?(Array)
    model = who.first
    model = case model
    when String then model
    when Class then model.name
    else
      model.class.name
    end
    [PREFIX, model.gsub("::", "/"), *who[1..-1]].compact.join("/")
  else
    who
  end
end
stat(key) click to toggle source
# File lib/statsn.rb, line 22
def stat(key)
  NewRelic::Agent.agent.stats_engine.get_stats_no_scope(key)
end