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.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/tracebin/reporter.rb', line 8

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

  if config.enable_ssl
    require 'net/https'
  else
    require 'net/http'
  end

  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.



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

def config
  @config
end

#loggerObject (readonly)

Returns the value of attribute logger.



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

def logger
  @logger
end

#storageObject (readonly)

Returns the value of attribute storage.



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

def storage
  @storage
end

Instance Method Details

#start!Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/tracebin/reporter.rb', line 27

def start!
  freq = config.report_frequency >= 5 ? config.report_frequency : 5
  @retries = 0

  @task = Concurrent::TimerTask.new execution_interval: freq 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



44
45
46
47
# File 'lib/tracebin/reporter.rb', line 44

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