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.



14
15
16
# File 'lib/new_relic/agent/stats_engine/stats_hash.rb', line 14

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

Instance Method Details

#==(other) ⇒ Object



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

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

#marshal_dumpObject



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

def marshal_dump
  Hash[self]
end

#marshal_load(hash) ⇒ Object



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

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

#merge!(other) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/new_relic/agent/stats_engine/stats_hash.rb', line 46

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) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/new_relic/agent/stats_engine/stats_hash.rb', line 30

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