Class: ZombiePassengerKiller::Reaper
- Inherits:
-
Object
- Object
- ZombiePassengerKiller::Reaper
- Defined in:
- lib/zombie_passenger_killer/reaper.rb
Instance Attribute Summary collapse
-
#out ⇒ Object
overwriteable for tests.
Instance Method Summary collapse
- #hunt_zombies ⇒ Object
-
#initialize(options) ⇒ Reaper
constructor
A new instance of Reaper.
- #lurk ⇒ Object
Constructor Details
#initialize(options) ⇒ Reaper
Returns a new instance of Reaper.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/zombie_passenger_killer/reaper.rb', line 6 def initialize() @history = {} @history_entries = [:history] || 5 @max_high_cpu = [:max] @high_cpu = [:cpu] || 70 @grace_time = [:grace] || 5 @pattern = [:pattern] || ' Rack: ' @show_times = [:show_times] || false @interval = [:interval] || 10 @verbose = [:verbose] @strace_time = 5 @out = STDOUT @rvmsudo = [:rvmsudo] end |
Instance Attribute Details
#out ⇒ Object
overwriteable for tests
4 5 6 |
# File 'lib/zombie_passenger_killer/reaper.rb', line 4 def out @out end |
Instance Method Details
#hunt_zombies ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/zombie_passenger_killer/reaper.rb', line 31 def hunt_zombies return unless active_pids_in_passenger_status = passenger_pids puts "Active pids in status: #{active_pids_in_passenger_status.inspect}" if @verbose active_processes_in_processlist = process_status puts "Active pids in processlist: #{active_processes_in_processlist.inspect}" if @verbose zombies = active_processes_in_processlist.map{|x| x[:pid] } - active_pids_in_passenger_status rescue Array.new puts "Zombies: #{zombies.inspect}" if @verbose # kill processes with high CPU if user wants it high_load = if @max_high_cpu store_current_cpu active_processes_in_processlist active_pids_in_passenger_status.select do |pid| (@history[pid] || []).count{|x| x > @high_cpu } >= @max_high_cpu end else [] end (high_load + zombies).each do |pid| kill_zombie pid end end |
#lurk ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/zombie_passenger_killer/reaper.rb', line 21 def lurk loop do hunt_zombies sleep @interval end rescue Interrupt log "Exiting..." raise $! end |