Sha256: 72ae76ec2ba4c2349aabdaba17a89ca12e9ec500e666086409ea84d50bab6643

Contents?: true

Size: 1.54 KB

Versions: 14

Compression:

Stored size: 1.54 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.

# A Hash-descended class for storing metric data in the NewRelic Agent.
#
# Keys are NewRelic::MetricSpec objects.
# Values are NewRelic::Agent::Stats objects.
#
# Missing keys will be automatically created as empty NewRelic::Agent::Stats
# instances, so use has_key? explicitly to check for key existence.
#
# This class makes no provisions for safe usage from multiple threads, such
# measures should be externally provided.
module NewRelic
  module Agent
    class StatsHash < ::Hash
      def initialize
        super { |hash, key| hash[key] = NewRelic::Agent::Stats.new }
      end

      def marshal_dump
        Hash[self]
      end

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

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

      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

      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
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
newrelic_rpm-3.6.3.111 lib/new_relic/agent/stats_engine/stats_hash.rb
newrelic_rpm-3.6.3.106 lib/new_relic/agent/stats_engine/stats_hash.rb
newrelic_rpm-3.6.3.105.beta lib/new_relic/agent/stats_engine/stats_hash.rb
newrelic_rpm-3.6.3.104 lib/new_relic/agent/stats_engine/stats_hash.rb
newrelic_rpm-3.6.3.103.beta lib/new_relic/agent/stats_engine/stats_hash.rb
newrelic_rpm-3.6.2.96 lib/new_relic/agent/stats_engine/stats_hash.rb
newrelic_rpm-3.6.2.90.beta lib/new_relic/agent/stats_engine/stats_hash.rb
newrelic_rpm-3.6.1.88 lib/new_relic/agent/stats_engine/stats_hash.rb
newrelic_rpm-3.6.1.87 lib/new_relic/agent/stats_engine/stats_hash.rb
newrelic_rpm-3.6.1.86.beta lib/new_relic/agent/stats_engine/stats_hash.rb
newrelic_rpm-3.6.1.85.beta lib/new_relic/agent/stats_engine/stats_hash.rb
newrelic_rpm-3.6.0.83 lib/new_relic/agent/stats_engine/stats_hash.rb
newrelic_rpm-3.6.0.78 lib/new_relic/agent/stats_engine/stats_hash.rb
newrelic_rpm-3.6.0.74.beta lib/new_relic/agent/stats_engine/stats_hash.rb