Sha256: 1d024e48cbeb0021bfa2f9a6b67c5a900914373c52100768c959e91edb1212a3

Contents?: true

Size: 1.67 KB

Versions: 18

Compression:

Stored size: 1.67 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.

module NewRelic
  module Agent
    class SamplerCollection
      include Enumerable

      def initialize(event_listener)
        @samplers = []
        event_listener.subscribe(:before_harvest) { poll_samplers }
      end

      def each(&blk)
        @samplers.each(&blk)
      end

      def sampler_class_registered?(sampler_class)
        self.any? { |s| s.class == sampler_class }
      end

      def poll_samplers
        @samplers.delete_if do |sampler|
          begin
            sampler.poll
            false # it's okay.  don't delete it.
          rescue => e
            ::NewRelic::Agent.logger.warn("Removing #{sampler} from list", e)
            true # remove the sampler
          end
        end
      end

      def add_sampler(sampler_class)
        if sampler_class.supported_on_this_platform?
          if !sampler_class_registered?(sampler_class)
            @samplers << sampler_class.new
            ::NewRelic::Agent.logger.debug("Registered #{sampler_class.name} for harvest time sampling.")
          else
            ::NewRelic::Agent.logger.warn("Ignoring addition of #{sampler_class.name} because it is already registered.")
          end
        else
          ::NewRelic::Agent.logger.debug("#{sampler_class.name} not supported on this platform.")
        end
      rescue NewRelic::Agent::Sampler::Unsupported => e
        ::NewRelic::Agent.logger.info("#{sampler_class.name} not available: #{e}")
      rescue => e
        ::NewRelic::Agent.logger.error("Error registering sampler:", e)
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
newrelic_rpm-3.7.1.188 lib/new_relic/agent/sampler_collection.rb
newrelic_rpm-3.7.1.182 lib/new_relic/agent/sampler_collection.rb
newrelic_rpm-3.7.1.180 lib/new_relic/agent/sampler_collection.rb
newrelic_rpm-3.7.0.177 lib/new_relic/agent/sampler_collection.rb
newrelic_rpm-3.7.0.174.beta lib/new_relic/agent/sampler_collection.rb
newrelic_rpm-3.6.9.171 lib/new_relic/agent/sampler_collection.rb
newrelic_rpm-3.6.8.168 lib/new_relic/agent/sampler_collection.rb
newrelic_rpm-3.6.8.164 lib/new_relic/agent/sampler_collection.rb
newrelic_rpm-3.6.7.159 lib/new_relic/agent/sampler_collection.rb
newrelic_rpm-3.6.7.159.beta lib/new_relic/agent/sampler_collection.rb
newrelic_rpm-3.6.7.152 lib/new_relic/agent/sampler_collection.rb
newrelic_rpm-3.6.6.147 lib/new_relic/agent/sampler_collection.rb
newrelic_rpm-3.6.5.130 lib/new_relic/agent/sampler_collection.rb
newrelic_rpm-3.6.4.122 lib/new_relic/agent/sampler_collection.rb
newrelic_rpm-3.6.4.113.beta lib/new_relic/agent/sampler_collection.rb
newrelic_rpm-3.6.3.111 lib/new_relic/agent/sampler_collection.rb
newrelic_rpm-3.6.3.106 lib/new_relic/agent/sampler_collection.rb
newrelic_rpm-3.6.3.105.beta lib/new_relic/agent/sampler_collection.rb