class Monitors::ViolationsRecorders::ResponseTime

Public Class Methods

process_attr() click to toggle source
# File lib/monitors/violations_recorders/response_time.rb, line 12
def process_attr
  :pid
end
process_is_violating?(process) click to toggle source
# File lib/monitors/violations_recorders/response_time.rb, line 16
def process_is_violating?(process)
  time = Cfg.response_time_threshold 
  phrase = nil
  begin 
    Timeout.timeout(Cfg.response_time_threshold) do 
      response = get_response(process)
      time = response.split("***").last.to_f
      phrase = response.match(Cfg.response_check_phrase)
    end
  rescue Timeout::Error
    return true
  end
  ( time > Cfg.response_time_threshold ) || !(phrase)
end
retries_limit() click to toggle source
# File lib/monitors/violations_recorders/response_time.rb, line 8
def retries_limit
  Cfg.response_time_check_retries
end

Private Class Methods

get_response(process) click to toggle source
# File lib/monitors/violations_recorders/response_time.rb, line 33
def get_response(process)
  `curl -s -w "***%{time_total}" --header "X-Backend-Host: #{Cfg.response_time_check_host}" --header "X-Phantom: true" #{process_url(process)}`
end
process_url(process) click to toggle source
# File lib/monitors/violations_recorders/response_time.rb, line 37
def process_url(process)
  "http://localhost:#{process.port}#{Cfg.response_time_check_path}"
end