Module: NewRelic::Agent::StatsEngine::Samplers

Included in:
NewRelic::Agent::StatsEngine
Defined in:
lib/new_relic/agent/stats_engine/samplers.rb

Overview

Contains statistics engine extensions to support the concept of samplers

Constant Summary collapse

POLL_PERIOD =

By default a sampler polls on harvest time, once a minute. However you can override #use_harvest_sampler? to return false and it will sample every POLL_PERIOD seconds on a background thread.

20

Instance Method Summary collapse

Instance Method Details

#add_harvest_sampler(sampler) ⇒ Object

Add a sampler to be invoked just before each harvest.



67
68
69
70
# File 'lib/new_relic/agent/stats_engine/samplers.rb', line 67

def add_harvest_sampler(sampler)
  add_sampler_to(harvest_samplers, sampler)
  log_added_sampler('harvest-time', sampler)
end

#add_sampler(sampler) ⇒ Object

Add an instance of Sampler to be invoked about every 10 seconds on a background thread.



61
62
63
64
# File 'lib/new_relic/agent/stats_engine/samplers.rb', line 61

def add_sampler(sampler)
  add_sampler_to(periodic_samplers, sampler)
  log_added_sampler('periodic', sampler)
end

#start_sampler_threadObject

starts the sampler thread which runs periodically, rather than at harvest time. This is deprecated, and should not actually be used - mo threads mo problems

returns unless there are actually periodic samplers to run



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/new_relic/agent/stats_engine/samplers.rb', line 23

def start_sampler_thread

  return if @sampler_thread && @sampler_thread.alive?

  # start up a thread that will periodically poll for metric samples
  return if periodic_samplers.empty?

  @sampler_thread = NewRelic::Agent::Thread.new('Sampler Tasks') do
    loop do
      now = Time.now
      begin
        sleep POLL_PERIOD
        poll periodic_samplers
      ensure
        NewRelic::Agent.instance.stats_engine \
          .get_stats_no_scope('Supportability/Samplers') \
          .record_data_point((Time.now - now).to_f)
      end
    end
  end
end