Class: NewRelic::TelemetrySdk::Harvester
- Inherits:
-
Object
- Object
- NewRelic::TelemetrySdk::Harvester
- Includes:
- Logger
- Defined in:
- lib/newrelic/telemetry_sdk/harvester.rb
Overview
This class handles sending data to New Relic automatically at configured intervals.
Instance Method Summary collapse
- #[](name) ⇒ Object
-
#initialize ⇒ Harvester
constructor
A new instance of Harvester.
- #interval ⇒ Object
-
#register(name, buffer, client) ⇒ Object
Register a pipeline (i.e. a buffer from which data can be harvested via a
flush
method and a client that can be used to send that data). - #running? ⇒ Boolean
-
#start ⇒ Object
Start scheduled harvests via this harvester.
-
#stop ⇒ Object
Stop scheduled harvests via this harvester.
Methods included from Logger
#clear_already_logged, #log_error, #log_once, logger, #logger, logger=, #logger=
Constructor Details
#initialize ⇒ Harvester
Returns a new instance of Harvester.
21 22 23 24 25 26 |
# File 'lib/newrelic/telemetry_sdk/harvester.rb', line 21 def initialize @pipelines = {} @shutdown = false @running = false @lock = Mutex.new end |
Instance Method Details
#[](name) ⇒ Object
54 55 56 |
# File 'lib/newrelic/telemetry_sdk/harvester.rb', line 54 def [] name @pipelines[name] end |
#interval ⇒ Object
58 59 60 |
# File 'lib/newrelic/telemetry_sdk/harvester.rb', line 58 def interval TelemetrySdk.config.harvest_interval end |
#register(name, buffer, client) ⇒ Object
Register a pipeline (i.e. a buffer from which data can be harvested via a flush
method and a client that can be used to send that data).
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/newrelic/telemetry_sdk/harvester.rb', line 42 def register name, buffer, client logger.info "Registering pipeline #{name}" @lock.synchronize do @pipelines[name] = { buffer: buffer, client: client } end rescue => e log_error "Encountered error while registering buffer #{name}.", e end |
#running? ⇒ Boolean
62 63 64 |
# File 'lib/newrelic/telemetry_sdk/harvester.rb', line 62 def running? @running end |
#start ⇒ Object
Start scheduled harvests via this harvester.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/newrelic/telemetry_sdk/harvester.rb', line 69 def start logger.info "Harvesting every #{interval} seconds" @running = true @harvest_thread = Thread.new do begin while !@shutdown do sleep interval harvest end harvest @running = false rescue => e log_error "Encountered error in harvester", e end end end |
#stop ⇒ Object
Stop scheduled harvests via this harvester. Any remaining buffered data will be sent before the harvest thread is stopped.
90 91 92 93 94 95 96 |
# File 'lib/newrelic/telemetry_sdk/harvester.rb', line 90 def stop logger.info "Stopping harvester" @shutdown = true @harvest_thread.join if @running rescue => e log_error "Encountered error stopping harvester", e end |