Class: Bounscale::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/bounscale/middlerware.rb

Constant Summary collapse

COLLECTOR_CLASSES =
[
  Bounscale::Collector::Cpu,
  Bounscale::Collector::Memory,
  Bounscale::Collector::Busyness,
  Bounscale::Collector::Throughput
]

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



12
13
14
# File 'lib/bounscale/middlerware.rb', line 12

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bounscale/middlerware.rb', line 16

def call(env)
  collector_instances = COLLECTOR_CLASSES.map do |klass|
    collector = klass.new
    collector.pre
    collector
  end
  
  app_response = @app.call(env)

  collector_instances.each do |collector|
    collector.post
  end
  
  Bounscale::Writer::HerokuWriter.new.write(collector_instances)
  return app_response
end