Class: TSSApp
- Inherits:
-
Sinatra::Application
- Object
- Sinatra::Application
- TSSApp
- Includes:
- Wilson::Web
- Defined in:
- lib/webapp.rb
Overview
The TSSApp class serves log files generated by the Tsung stress testing tool.
Instance Method Summary collapse
-
#/ ⇒ Object
Shows the list of all logs present on the machine.
-
#list_dirs(logdirs) ⇒ String<text/html>
Generates a HTML document listing of all logs present on the machine.
-
#run_stats(dir, force = false) ⇒ String
Runs the report generation.
-
#zip(dir, filename) ⇒ undefined
Creates a zip file out of a directory.
Instance Method Details
#/ ⇒ Object
Shows the list of all logs present on the machine.
38 39 40 41 42 |
# File 'lib/webapp.rb', line 38 get '/' do logdirs = (Dir.entries(.logdir) - [".", ".."]).sort logdirs.reject! {|file| file =~ /\.zip/ } list_dirs(logdirs) end |
#list_dirs(logdirs) ⇒ String<text/html>
Generates a HTML document listing of all logs present on the machine.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/webapp.rb', line 115 def list_dirs(logdirs) doc = Markaby::Builder.new doc.html do head do title "Logpickin'" end body do h1 "Pick a log:" ul.logs do logdirs.each do |dir| li.log do a "Log #{dir}", :href => "/#{dir}/report.html" a "As zip", :href => "/#{dir}.zip" end end end end end end |
#run_stats(dir, force = false) ⇒ String
Runs the report generation. If a report already exists, it wont be generated a second time, unless forced explicitly.
83 84 85 86 87 88 89 90 |
# File 'lib/webapp.rb', line 83 def run_stats(dir, force = false) Dir.chdir( File.join(.logdir, dir) ) do unless File.exists?('report.html') && force == false system(.tsung_stats) end File.read('report.html') end end |
#zip(dir, filename) ⇒ undefined
Creates a zip file out of a directory.
99 100 101 102 103 104 105 106 107 |
# File 'lib/webapp.rb', line 99 def zip(dir, filename) Dir.chdir( File.join(.logdir) ) do unless File.exists?("#{dir}.zip") Zip::ZipFile.open("#{filename}.zip", true) do |zf| Dir["#{dir}/**/*"].each { |f| zf.add(f, f) } end end end end |