Class: Tracebin::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/tracebin/reporter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(storage = Tracebin::Agent.storage, config = Tracebin::Agent.config, logger = Tracebin::Agent.logger) ⇒ Reporter

Returns a new instance of Reporter.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/tracebin/reporter.rb', line 9

def initialize(storage = Tracebin::Agent.storage, config = Tracebin::Agent.config, logger = Tracebin::Agent.logger)
  @logger = logger
  @config = config
  @storage = storage

  host = Tracebin::Agent.config.host
  path = Tracebin::Agent.config.report_path
  @uri = URI("#{host}/#{path}")

  @bin_id = Tracebin::Agent.config.bin_id
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/tracebin/reporter.rb', line 7

def config
  @config
end

#loggerObject (readonly)

Returns the value of attribute logger.



7
8
9
# File 'lib/tracebin/reporter.rb', line 7

def logger
  @logger
end

#storageObject (readonly)

Returns the value of attribute storage.



7
8
9
# File 'lib/tracebin/reporter.rb', line 7

def storage
  @storage
end

Instance Method Details

#start!Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/tracebin/reporter.rb', line 21

def start!
  @task = Concurrent::TimerTask.new do
    unless storage.unloaded?
      payload = storage.unload
      res = send_data payload

      handle_response res, payload
    end
  end

  logger.info 'TRACEBIN: Reporter starting.'
  @task.execute
end

#stop!Object



35
36
37
38
# File 'lib/tracebin/reporter.rb', line 35

def stop!
  logger.info 'TRACEBIN: Reporter stopping. The agent will no longer report metrics to the server.'
  @task.shutdown if @task && @task.running?
end