Class: BaselineRedRpm::Reporters::JsonClient

Inherits:
Object
  • Object
show all
Defined in:
lib/baseline_red_rpm/reporters/json_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = { :url => nil, :collector => nil, :flush_interval => nil }) ⇒ JsonClient

Returns a new instance of JsonClient.



13
14
15
16
17
# File 'lib/baseline_red_rpm/reporters/json_client.rb', line 13

def initialize(opts = { :url => nil, :collector => nil, :flush_interval => nil })
  @collector = opts[:collector]
  @flush_interval = opts[:flush_interval]
  @spans_uri = URI.parse(opts[:url])
end

Instance Attribute Details

#sample_memoryObject

Returns the value of attribute sample_memory.



11
12
13
# File 'lib/baseline_red_rpm/reporters/json_client.rb', line 11

def sample_memory
  @sample_memory
end

Instance Method Details

#startObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/baseline_red_rpm/reporters/json_client.rb', line 19

def start
  @thread = Thread.new do
    loop do
      memory_stats = MemoryProfiler.stop

      emit_batch(@collector.retrieve, memory_stats)

      start_memory_profiler
      sleep @flush_interval
    end
  end
end

#stopObject



32
33
34
35
# File 'lib/baseline_red_rpm/reporters/json_client.rb', line 32

def stop
  @thread.terminate if @thread
  emit_batch(@collector.retrieve)
end