Class: TSSApp
- Sinatra::Application
- TSSApp
Included Modules
Wilson::Web
The TSSApp class serves log files generated by the Tsung stress testing tool.
Sinatra Routes
/
Shows the list of all logs present on the machine.
36 37 38 39 40 |
# File 'lib/webapp.rb', line 36 get '/' do logdirs = (Dir.entries(.logdir) - [".", ".."]).sort logdirs.reject! {|file| file =~ /\.zip/ } list_dirs(logdirs) end |
/:dir/report.html
Shows a report. If the report is not generated already, it will be.
51 52 53 |
# File 'lib/webapp.rb', line 51 get '/:dir/report.html' do run_stats(params[:dir]) end |
/:dir.zip
Delivers a report as zip file. If not generated, report generation takes place.
62 63 64 65 66 67 68 69 70 |
# File 'lib/webapp.rb', line 62 get '/:dir.zip' do filename = params[:dir].gsub(/:/, '-') unless File.exists?(File.join(.logdir, "#{filename}.zip")) zip(params[:dir], filename) end ("#{filename}.zip") content_type("application/zip") File.read(File.join(.logdir, "#{filename}.zip")) end |
Public Visibility
Public Instance Method Summary
#list_dirs(logdirs) |
Generates a HTML document listing of all logs present on the machine. Returns: String<text/html> |
---|---|
#run_stats(dir, force = false) |
Runs the report generation. Returns: String |
#zip(dir, filename) |
Creates a zip file out of a directory. Returns: undefined |
Public Instance Method Details
list_dirs
Generates a HTML document listing of all logs present on the machine.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/webapp.rb', line 113 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
Runs the report generation. If a report already exists, it wont be generated a second time, unless forced explicitly.
81 82 83 84 85 86 87 88 |
# File 'lib/webapp.rb', line 81 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
Creates a zip file out of a directory.
97 98 99 100 101 102 103 104 105 |
# File 'lib/webapp.rb', line 97 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 |