Class: NewRelic::Agent::StatsHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/new_relic/agent/stats_engine/stats_hash.rb

Instance Method Summary collapse

Constructor Details

#initializeStatsHash

Returns a new instance of StatsHash.



18
19
20
# File 'lib/new_relic/agent/stats_engine/stats_hash.rb', line 18

def initialize
  super { |hash, key| hash[key] = NewRelic::Agent::Stats.new }
end

Instance Method Details

#==(other) ⇒ Object



30
31
32
# File 'lib/new_relic/agent/stats_engine/stats_hash.rb', line 30

def ==(other)
  Hash[self] == Hash[other]
end

#marshal_dumpObject



22
23
24
# File 'lib/new_relic/agent/stats_engine/stats_hash.rb', line 22

def marshal_dump
  Hash[self]
end

#marshal_load(hash) ⇒ Object



26
27
28
# File 'lib/new_relic/agent/stats_engine/stats_hash.rb', line 26

def marshal_load(hash)
  self.merge!(hash)
end

#merge!(other) ⇒ Object



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

def merge!(other)
  other.each do |key,val|
    if self.has_key?(key)
      self[key].merge!(val)
    else
      self[key] = val
    end
  end
  self
end

#record(metric_specs, value = nil, aux = nil) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/new_relic/agent/stats_engine/stats_hash.rb', line 34

def record(metric_specs, value=nil, aux=nil)
  Array(metric_specs).each do |metric_spec|
    stats = self[metric_spec]
    if block_given?
      yield stats
    else
      case value
      when Numeric
        aux ||= value
        stats.record_data_point(value, aux)
      when :apdex_s, :apdex_t, :apdex_f
        stats.record_apdex(value, aux)
      when NewRelic::Agent::Stats
        stats.merge!(value)
      end
    end
  end
end

#resolve_scopes!(resolved_scope) ⇒ Object



64
65
66
67
68
69
# File 'lib/new_relic/agent/stats_engine/stats_hash.rb', line 64

def resolve_scopes!(resolved_scope)
  placeholder = StatsEngine::SCOPE_PLACEHOLDER.to_s
  each_pair do |spec, stats|
    spec.scope = resolved_scope if spec.scope == placeholder
  end
end