Class: GitLab::Monitor::WebExporter::MemoryKillerMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_monitor/web_exporter.rb

Overview

A middleware to kill the process if we exceeded a certain threshold

Instance Method Summary collapse

Constructor Details

#initialize(app, memory_threshold) ⇒ MemoryKillerMiddleware

Returns a new instance of MemoryKillerMiddleware.



10
11
12
13
# File 'lib/gitlab_monitor/web_exporter.rb', line 10

def initialize(app, memory_threshold)
  @app = app
  @memory_threshold = memory_threshold.to_i * 1024
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/gitlab_monitor/web_exporter.rb', line 15

def call(env)
  if memory_usage > @memory_threshold
    puts "Memory usage of #{memory_usage} exceeded threshold of #{@memory_threshold}, signalling KILL"
    Process.kill("KILL", $PID)
  end

  @app.call(env)
end