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 =

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.



47
48
49
50
51
52
53
54
# File 'lib/new_relic/agent/stats_engine/samplers.rb', line 47

def add_harvest_sampler sampler
  harvest_samplers.each do |s|
    raise "Sampler #{sampler.id} is already registered.  Don't call add_sampler directly anymore." if s.id == sampler.id
  end
  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.



37
38
39
40
41
42
43
44
# File 'lib/new_relic/agent/stats_engine/samplers.rb', line 37

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

#start_sampler_threadObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/new_relic/agent/stats_engine/samplers.rb', line 17

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 = Thread.new do
    while true do
      begin
        sleep POLL_PERIOD
        poll periodic_samplers
      end
    end
  end
  @sampler_thread['newrelic_label'] = 'Sampler Tasks'
end