Class: Lamby::ColdStartMetrics

Inherits:
Object
  • Object
show all
Defined in:
lib/lamby/cold_start_metrics.rb

Constant Summary collapse

NAMESPACE =
'Lamby'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(proactive_init) ⇒ ColdStartMetrics

Returns a new instance of ColdStartMetrics.



25
26
27
28
29
# File 'lib/lamby/cold_start_metrics.rb', line 25

def initialize(proactive_init)
  @proactive_init = proactive_init
  @metrics = []
  @properties = {}
end

Class Method Details

.clear!Object



18
19
20
21
# File 'lib/lamby/cold_start_metrics.rb', line 18

def clear!
  @cold_start = true
  @cold_start_time = (Time.now.to_f * 1000).to_i
end

.instrument!Object



10
11
12
13
14
15
16
# File 'lib/lamby/cold_start_metrics.rb', line 10

def instrument!
  return unless @cold_start
  @cold_start = false
  now = (Time.now.to_f * 1000).to_i
  proactive_init = (now - @cold_start_time) > 10_000
  new(proactive_init).instrument!
end

Instance Method Details

#instrument!Object



31
32
33
34
35
# File 'lib/lamby/cold_start_metrics.rb', line 31

def instrument!
  name = @proactive_init ? 'ProactiveInit' : 'ColdStart'
  put_metric name, 1, 'Count'
  puts JSON.dump(message)
end