Sha256: 8e7b8aa0cf61627a42ff0183a9a94d11c4741575b7282324b5f7afcc28dd2a39

Contents?: true

Size: 1.75 KB

Versions: 36

Compression:

Stored size: 1.75 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 = []

      class << self
        attr_reader :shorthand_name
      end

      def self.named(new_name)
        @shorthand_name = new_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 shorthand_name
          config_key = "disable_#{shorthand_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.shorthand_name
      end

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

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
newrelic_rpm-6.11.0.365 lib/new_relic/agent/sampler.rb
newrelic_rpm-6.10.0.364 lib/new_relic/agent/sampler.rb
newrelic_rpm-6.9.0.363 lib/new_relic/agent/sampler.rb
newrelic_rpm-6.8.0.360 lib/new_relic/agent/sampler.rb
newrelic_rpm-6.7.0.359 lib/new_relic/agent/sampler.rb
newrelic_rpm-6.6.0.358 lib/new_relic/agent/sampler.rb
newrelic_rpm-6.5.0.357 lib/new_relic/agent/sampler.rb
newrelic_rpm-6.4.0.356 lib/new_relic/agent/sampler.rb
newrelic_rpm-6.3.0.355 lib/new_relic/agent/sampler.rb
newrelic_rpm-6.2.0.354 lib/new_relic/agent/sampler.rb
newrelic_rpm-6.1.0.352 lib/new_relic/agent/sampler.rb
newrelic_rpm-6.0.0.351 lib/new_relic/agent/sampler.rb
newrelic_rpm-5.7.0.350 lib/new_relic/agent/sampler.rb
newrelic_rpm-5.6.0.349 lib/new_relic/agent/sampler.rb
newrelic_rpm-5.5.0.348 lib/new_relic/agent/sampler.rb
newrelic_rpm-5.4.0.347 lib/new_relic/agent/sampler.rb
newrelic_rpm-5.3.0.346 lib/new_relic/agent/sampler.rb
newrelic_rpm-5.2.0.345 lib/new_relic/agent/sampler.rb
newrelic_rpm-5.1.0.344 lib/new_relic/agent/sampler.rb
newrelic_rpm-5.0.0.342 lib/new_relic/agent/sampler.rb