Class: TSSApp

Inherits:
Sinatra::Application
  • Object
show all
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

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(options.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.

Parameters:

  • logdirs (Array<String>)

    The directories that contain logs.

Returns:

  • (String<text/html>)

    The generated document.



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.

Parameters:

  • dir (String)

    The logfile directory of the report.

  • force (true, false) (defaults to: false)

    If set to true, the report gets created unconditionally.

Returns:

  • (String)

    The contents of #dir/report.html



83
84
85
86
87
88
89
90
# File 'lib/webapp.rb', line 83

def run_stats(dir, force = false)
  Dir.chdir( File.join(options.logdir, dir) ) do
    unless File.exists?('report.html') && force == false
      system(options.tsung_stats)
    end
    File.read('report.html')
  end
end

#zip(dir, filename) ⇒ undefined

Creates a zip file out of a directory.

Parameters:

  • dir (String)

    The directories name.

  • filename (String)

    The output filename.

Returns:

  • (undefined)

    unspecified



99
100
101
102
103
104
105
106
107
# File 'lib/webapp.rb', line 99

def zip(dir, filename)
  Dir.chdir( File.join(options.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