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

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

Constant Summary collapse

POLL_PERIOD =
10

Instance Method Summary collapse

Instance Method Details

#add_harvest_sampler(sampler) ⇒ Object

Add a sampler to be invoked just before each harvest.



42
43
44
45
46
# File 'lib/new_relic/agent/stats_engine/samplers.rb', line 42

def add_harvest_sampler sampler
  harvest_samplers << sampler
  sampler.stats_engine = self
  log.debug "Adding harvest time sampler: #{sampler.id.to_s}"
end

#add_sampler(sampler) ⇒ Object

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



32
33
34
35
36
37
38
39
# File 'lib/new_relic/agent/stats_engine/samplers.rb', line 32

def add_sampler sampler
  periodic_samplers.each do |s|
    raise "Sampler #{sampler.id} is already registered.  Don't call add_sampler directly anymore." if s.id == sampler.id
  end
  periodic_samplers << sampler
  sampler.stats_engine = self
  log.debug "Adding sampler #{sampler.id.to_s}"
end

#spawn_sampler_threadObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/new_relic/agent/stats_engine/samplers.rb', line 13

def spawn_sampler_thread
  
  return if !@sampler_process.nil? && @sampler_process == $$ 
  
  # start up a thread that will periodically poll for metric samples
  @sampler_thread = Thread.new do
    while true do
      begin
        sleep POLL_PERIOD
        poll periodic_samplers
      end
    end
  end
  @sampler_thread['newrelic_label'] = 'Sampler Tasks'
  @sampler_process = $$
end