class Aws::SiteMonitor::CLI
Public Instance Methods
add()
click to toggle source
# File lib/aws/site_monitor/cli.rb, line 24 def add site = ::Aws::SiteMonitor::Site.create(:url => options.url, :instance_ids => options.instance_ids) puts "added #{options[:url]} to watchlist" end
check_killswitch()
click to toggle source
# File lib/aws/site_monitor/cli.rb, line 97 def check_killswitch puts "CHECKING KILLSWITCH #{options.killswitch_url}" result = `curl -s -o /dev/null -I -w "%{http_code}" -L #{options.killswitch_url}` puts result kill_process! if result[0] != "2" end
check_killswitch?()
click to toggle source
# File lib/aws/site_monitor/cli.rb, line 104 def check_killswitch? !!options.killswitch_url end
clear_events()
click to toggle source
# File lib/aws/site_monitor/cli.rb, line 52 def clear_events ::Aws::SiteMonitor::Event.all.map(&:destroy) end
configure!()
click to toggle source
# File lib/aws/site_monitor/cli.rb, line 57 def configure! configure_traps end
configure_traps()
click to toggle source
Configure signal traps.
# File lib/aws/site_monitor/cli.rb, line 62 def configure_traps exit_signals = [:INT, :TERM] exit_signals << :QUIT unless defined?(JRUBY_VERSION) exit_signals.each do |signal| trap(signal) do puts "Stopping" exit(0) end end end
kill_process!()
click to toggle source
because we are in a new thread with the timer task, exit/abort wont work
# File lib/aws/site_monitor/cli.rb, line 109 def kill_process! ::Process.kill 9, ::Process.pid end
list_events()
click to toggle source
# File lib/aws/site_monitor/cli.rb, line 46 def list_events events = ::Aws::SiteMonitor::Event.all.map(&:attributes).join("\n") puts events.inspect end
ls()
click to toggle source
# File lib/aws/site_monitor/cli.rb, line 40 def ls sites = ::Aws::SiteMonitor::Site.all.map(&:attributes).join("\n") puts sites.inspect end
monitor_task()
click to toggle source
# File lib/aws/site_monitor/cli.rb, line 74 def monitor_task @monitor_task ||= ::Concurrent::TimerTask.new( execution_interval: options.check_every_seconds, timeout_interval: options.check_every_seconds ) do check_killswitch if check_killswitch? ::Aws::SiteMonitor::Site.all.each do |site| puts "MAKING REQUEST TO #{site[:url]}" result = `curl -s -o /dev/null -I -w "%{http_code}" --max-time #{options.request_timeout_seconds} #{site[:url]}` if result[0] == "2" puts "GOT 200 EVERYTHING OK" site.reset_failure_count else site.track_failure ::Aws::SiteMonitor::Event.create(:status_code => result) site.handle_failure!(options) end end end end
remove()
click to toggle source
# File lib/aws/site_monitor/cli.rb, line 31 def remove site = ::Aws::SiteMonitor::Site.find_by(:url => options.url) raise ::StandardError.new("SiteNotFound #{options.url}") if !site site.destroy puts "removed #{site[:url]} from watchlist" end
start()
click to toggle source
# File lib/aws/site_monitor/cli.rb, line 11 def start configure! start_monitoring! sleep rescue => e puts "ERROR #{e.message}" start_monitoring! end
start_monitoring!()
click to toggle source
# File lib/aws/site_monitor/cli.rb, line 113 def start_monitoring! monitor_task.shutdown if @monitor_task @monitor_task = nil monitor_task.execute end