class GitLab::Exporter::WebExporter::MemoryKillerMiddleware
A middleware to kill the process if we exceeded a certain threshold
Public Class Methods
new(app, memory_threshold)
click to toggle source
# File lib/gitlab_exporter/web_exporter.rb, line 10 def initialize(app, memory_threshold) @app = app @memory_threshold = memory_threshold.to_i * 1024 end
Public Instance Methods
call(env)
click to toggle source
# File lib/gitlab_exporter/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
Private Instance Methods
memory_usage()
click to toggle source
# File lib/gitlab_exporter/web_exporter.rb, line 26 def memory_usage io = IO.popen(%W[ps -o rss= -p #{$PID}]) mem = io.read io.close return 0 unless $CHILD_STATUS.to_i.zero? mem.to_i end