Class: HomeWrecker

Inherits:
Thor
  • Object
show all
Defined in:
lib/home_wrecker.rb

Instance Method Summary collapse

Instance Method Details

#wreckObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/home_wrecker.rb', line 29

def wreck
  $extra_args ||= ""
  siege_check = `which siege`
  if siege_check == ""
    say "please ensure that siege is installed. run: $ brew install siege", :red
    exit
  end
  file = File.new("seige_output.html", "w")
  file.puts '<body><head><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" /><style>.url{background-color: orange;} td{white-space: pre; vertical-align:top}</style></head><table class="table table-striped"><thead>'
  $urls.each do |url|
    file.puts "<th>#{url}</th>"
  end
  file.puts '</thead><tbody>'
  $endpoints.each do |endpoint|
    file.puts '<tr align="top">'
    $urls.each do |url|
      final_url = "#{url}/#{endpoint}"
      say "hitting #{final_url} for #{$seconds} seconds", :green
      cmd = "siege -v -b -t#{$seconds}S #{final_url} #{$extra_args}"
      file.puts '<td>'
      file.puts "<span class='url'>#{final_url}</span><br />"
      f = `#{cmd} 2>&1`
      if $verbose
        file.puts f
      else
        file.puts f.gsub(/\n\e.*$/, '')
      end
      file.puts '</td>'
    end
    file.puts '</tr>'
  end
  file.puts '</table></body>'
  `open seige_output.html`
end