Created
September 11, 2018 16:42
-
-
Save ilkelma/1557c3751cc69a6cae322e20772a190d to your computer and use it in GitHub Desktop.
interview coding exercise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
passenger_status = %x( ./passenger-status.rb ) | |
lines = passenger_status.split("*") | |
# lines = passenger_status.match /Uptime.*CPU/m | |
# puts lines | |
# /Uptime.*CPU/ | |
# lines.select! { |line| line =~ /^\s*\*/ } | |
lines = lines.drop(1) | |
passenger_processes = lines.map do |line| | |
line = line.split(/:|\s/) | |
# { | |
# :pid => line[1].rstrip, | |
# :sessions => line[3].to_i, | |
# :cpu => line[10].gsub("%", "").to_i, | |
# :memory => line[13].gsub("M", "").to_i | |
# } | |
# if line[4].to_i > 5 | |
# puts "Killing #{line[2]} with #{line[4]} active sessions" | |
# end | |
line.each_with_index do |token, i| | |
puts "#{token} #{i}" | |
end | |
end | |
passenger_processes.each do |process| | |
if process[:memory] > 700 | |
puts "Killing process #{process[:pid]} with memory usage #{process[:memory]}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment