Sha256: b5b606372b405b2a69a3c1343008dccf865c0e9a85afc49046acb58d4f85d379

Contents?: true

Size: 1.69 KB

Versions: 32

Compression:

Stored size: 1.69 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 Sampler is used to capture meaningful metrics in a background thread
# periodically.  They will be invoked about once a minute, each time the agent
# sends data to New Relic's servers.
#
# Samplers can be added to New Relic by subclassing NewRelic::Agent::Sampler.
# Instances are created when the agent is enabled and installed.  Subclasses
# are registered for instantiation automatically.
module NewRelic
  module Agent
    class Sampler

      # Exception denotes a sampler is not available and it will not be registered.
      class Unsupported < StandardError;  end

      attr_reader :id
      @sampler_classes = []

      def self.named(new_name)
        @name = new_name
      end

      def self.name
        @name
      end

      def self.inherited(subclass)
        @sampler_classes << subclass
      end

      # Override with check.  Called before instantiating.
      def self.supported_on_this_platform?
        true
      end

      def self.enabled?
        if @name
          config_key = "disable_#{@name}_sampler"
          !(Agent.config[config_key])
        else
          true
        end
      end

      def self.sampler_classes
        @sampler_classes
      end

      # The ID passed in here is unused by our code, but is preserved in case
      # we have clients who are defining their own subclasses of this class, and
      # expecting to be able to call super with an ID.
      def initialize(id=nil)
        @id = id || self.class.name
      end

      def poll
        raise "Implement in the subclass"
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 2 rubygems

Version Path
newrelic_rpm-3.16.2.321 lib/new_relic/agent/sampler.rb
newrelic_rpm-3.16.1.320 lib/new_relic/agent/sampler.rb
newrelic_rpm-3.16.0.318 lib/new_relic/agent/sampler.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.15.2.317/lib/new_relic/agent/sampler.rb
newrelic_rpm-3.15.2.317 lib/new_relic/agent/sampler.rb
newrelic_rpm-3.15.1.316 lib/new_relic/agent/sampler.rb
newrelic_rpm-3.15.0.314 lib/new_relic/agent/sampler.rb
newrelic_rpm-3.14.3.313 lib/new_relic/agent/sampler.rb
newrelic_rpm-3.14.2.312 lib/new_relic/agent/sampler.rb
newrelic_rpm-3.14.1.311 lib/new_relic/agent/sampler.rb
newrelic_rpm-3.14.0.305 lib/new_relic/agent/sampler.rb
newrelic_rpm-3.13.2.302 lib/new_relic/agent/sampler.rb
newrelic_rpm-3.13.1.300 lib/new_relic/agent/sampler.rb
newrelic_rpm-3.13.0.299 lib/new_relic/agent/sampler.rb
newrelic_rpm-3.12.1.298 lib/new_relic/agent/sampler.rb
newrelic_rpm-3.12.0.288 lib/new_relic/agent/sampler.rb
newrelic_rpm-3.11.2.286 lib/new_relic/agent/sampler.rb
newrelic_rpm-3.11.1.284 lib/new_relic/agent/sampler.rb
newrelic_rpm-3.11.0.283 lib/new_relic/agent/sampler.rb
newrelic_rpm-3.10.0.279 lib/new_relic/agent/sampler.rb