Class: NewRelic::Agent::TransactionMetrics

Inherits:
Object
  • Object
show all
Defined in:
lib/new_relic/agent/transaction_metrics.rb

Constant Summary collapse

DEFAULT_PROC =
proc { |hash, name| hash[name] = NewRelic::Agent::Stats.new }

Instance Method Summary collapse

Constructor Details

#initializeTransactionMetrics

Returns a new instance of TransactionMetrics.



15
16
17
18
19
# File 'lib/new_relic/agent/transaction_metrics.rb', line 15

def initialize
  @lock = Mutex.new
  @unscoped = Hash.new(&DEFAULT_PROC)
  @scoped = Hash.new(&DEFAULT_PROC)
end

Instance Method Details

#[](key) ⇒ Object



41
42
43
# File 'lib/new_relic/agent/transaction_metrics.rb', line 41

def [](key)
  @unscoped[key]
end

#_record_metrics(names, value, aux, target, &blk) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/new_relic/agent/transaction_metrics.rb', line 53

def _record_metrics(names, value, aux, target, &blk)
  # This looks dumb, but we're avoiding an extra Array allocation.
  case names
  when Array
    names.each do |name|
      @lock.synchronize { target[name].record(value, aux, &blk) }
    end
  else
    @lock.synchronize { target[names].record(value, aux, &blk) }
  end
end

#each_scopedObject



49
50
51
# File 'lib/new_relic/agent/transaction_metrics.rb', line 49

def each_scoped
  @lock.synchronize { @scoped.each { |name, stats| yield(name, stats) } }
end

#each_unscopedObject



45
46
47
# File 'lib/new_relic/agent/transaction_metrics.rb', line 45

def each_unscoped
  @lock.synchronize { @unscoped.each { |name, stats| yield(name, stats) } }
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/new_relic/agent/transaction_metrics.rb', line 37

def has_key?(key)
  @unscoped.has_key?(key)
end

#record_scoped_and_unscoped(names, value = nil, aux = nil, &blk) ⇒ Object

As a general rule, when recording a scoped metric, the corresponding unscoped metric should always be recorded as well.

As an optimization, scoped metrics are representated within this class only by their entries in the @scoped Hash, and it’s up to clients to propagate them into unscoped metrics as well when instances of this class are merged into the global metric store.



29
30
31
# File 'lib/new_relic/agent/transaction_metrics.rb', line 29

def record_scoped_and_unscoped(names, value = nil, aux = nil, &blk)
  _record_metrics(names, value, aux, @scoped, &blk)
end

#record_unscoped(names, value = nil, aux = nil, &blk) ⇒ Object



33
34
35
# File 'lib/new_relic/agent/transaction_metrics.rb', line 33

def record_unscoped(names, value = nil, aux = nil, &blk)
  _record_metrics(names, value, aux, @unscoped, &blk)
end