class OneApm::Collector::StatsHash
Attributes
harvested_at[RW]
started_at[RW]
Public Class Methods
new(started_at=Time.now)
click to toggle source
Calls superclass method
# File lib/one_apm/collector/stats_engine/stats_hash.rb, line 27 def initialize(started_at=Time.now) @started_at = started_at.to_f super() { |hash, key| hash[key] = OneApm::Metrics::Stats.new } end
Public Instance Methods
==(other)
click to toggle source
# File lib/one_apm/collector/stats_engine/stats_hash.rb, line 41 def ==(other) Hash[self] == Hash[other] end
marshal_dump()
click to toggle source
# File lib/one_apm/collector/stats_engine/stats_hash.rb, line 32 def marshal_dump [@started_at, Hash[self]] end
marshal_load(data)
click to toggle source
# File lib/one_apm/collector/stats_engine/stats_hash.rb, line 36 def marshal_load(data) @started_at = data.shift self.merge!(data.shift) end
merge!(other)
click to toggle source
# File lib/one_apm/collector/stats_engine/stats_hash.rb, line 75 def merge!(other) if other.is_a?(StatsHash) && other.started_at < @started_at @started_at = other.started_at end other.each do |key, val| merge_or_insert(key, val) end self end
merge_or_insert(metric_spec, stats)
click to toggle source
# File lib/one_apm/collector/stats_engine/stats_hash.rb, line 96 def merge_or_insert(metric_spec, stats) if self.has_key?(metric_spec) self[metric_spec].merge!(stats) else self[metric_spec] = stats end end
merge_transaction_metrics!(txn_metrics, scope)
click to toggle source
# File lib/one_apm/collector/stats_engine/stats_hash.rb, line 85 def merge_transaction_metrics!(txn_metrics, scope) txn_metrics.each_unscoped do |name, stats| spec = OneApm::MetricSpec.new(name) merge_or_insert(spec, stats) end txn_metrics.each_scoped do |name, stats| spec = OneApm::MetricSpec.new(name, scope) merge_or_insert(spec, stats) end end
record(metric_specs, value=nil, aux=nil, &blk)
click to toggle source
# File lib/one_apm/collector/stats_engine/stats_hash.rb, line 51 def record(metric_specs, value=nil, aux=nil, &blk) Array(metric_specs).each do |metric_spec| stats = nil begin stats = self[metric_spec] rescue NoMethodError => e # This only happen in the case of a corrupted default_proc # Side-step it manually, notice the issue, and carry on.... OneApm::Manager.agent.error_collector. \ notice_agent_error(StatsHashLookupError.new(e, self, metric_spec)) stats = OneApm::Metrics::Stats.new self[metric_spec] = stats # Try to restore the default_proc so we won't continually trip the error if respond_to?(:default_proc=) self.default_proc = Proc.new { |hash, key| hash[key] = OneApm::Metrics::Stats.new } end end stats.record(value, aux, &blk) end end