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.



63
64
65
66
# File 'lib/new_relic/agent/stats_engine/samplers.rb', line 63

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.



57
58
59
60
# File 'lib/new_relic/agent/stats_engine/samplers.rb', line 57

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