Class: DynoscaleRuby::Recorder

Inherits:
Object
  • Object
show all
Extended by:
Logger
Includes:
Singleton
Defined in:
lib/dynoscale_ruby/recorder.rb

Constant Summary collapse

REPORT_RECORDING_FREQ =

seconds

5

Class Method Summary collapse

Methods included from Logger

logger

Class Method Details

.record!(request_calculator, workers) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/dynoscale_ruby/recorder.rb', line 13

def self.record!(request_calculator, workers)
  is_dev = ENV['DYNOSCALE_DEV'] == 'true'
  dyno = is_dev ? "dev.1" : ENV['DYNO']
  
  queue_time = request_calculator.request_queue_time
  current_time = Time.now

  @@current_report ||= Report.new(current_time + REPORT_RECORDING_FREQ)
  
  if queue_time
    @@current_report&.add_measurement(current_time, queue_time, 'web', nil)
    Logger.logger.debug "Web measurement #{current_time}, #{queue_time} recorded in report."
  end

  workers.each do |worker|
    if worker.enabled?
      queue_latencies = worker.queue_latencies
      queue_latencies.each do |queue, latency, depth|
        @@current_report&.add_measurement(current_time, latency, "#{worker.name}:#{queue}", nil)
        Logger.logger.debug "#{worker.name.capitalize} worker measurement #{current_time}, #{latency} recorded in report."
      end
    end
  end

  @@reports ||= {}
  @@reports[@@current_report&.publish_timestamp] = @@current_report
  @@reports.values
end

.remove_published_reports!(reports) ⇒ Object



47
48
49
50
51
52
# File 'lib/dynoscale_ruby/recorder.rb', line 47

def self.remove_published_reports!(reports)
  reports.each do |report|
    @@current_report = nil if report.publish_timestamp == @@current_report.publish_timestamp
    @@reports.delete(report.publish_timestamp)
  end
end

.reportsObject



42
43
44
45
# File 'lib/dynoscale_ruby/recorder.rb', line 42

def self.reports
  @@reports ||= {}
  @@reports.values || []
end