Class: TSSApp

  • Sinatra::Application
    • TSSApp

Included Modules

Wilson::Web

The TSSApp class serves log files generated by the Tsung stress testing tool.

Meta Tags

Resource: xml

    <?xml encoding="utf-8">
    <report>
      bla
    </report>

Sinatra Routes

/

Shows the list of all logs present on the machine.

Meta Tags

Output Types:

[text/html]

Output Languages:

[en-US]
[View source]


36
37
38
39
40
# File 'lib/webapp.rb', line 36

get '/' do
  logdirs = (Dir.entries(options.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.

Meta Tags

Matched URL Parameters:

dir

The date on which the measurement was taken.

GET Parameters:

force

If present and set to any value, regeneration of the report is forced

Output Types:

[text/html]

Output Languages:

[en-US]
[View source]


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.

Meta Tags

Matched URL Parameters:

[dir]

The date on which the measurement was taken.

Output Types:

[application/zip]
[View source]


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(options.logdir, "#{filename}.zip"))
    zip(params[:dir], filename)
  end
  attachment("#{filename}.zip")
  content_type("application/zip")
  File.read(File.join(options.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

public String<text/html> list_dirs(logdirs)

Generates a HTML document listing of all logs present on the machine.

Meta Tags

Parameters:

[Array<String>] logdirs

The directories that contain logs.

Returns:

[String<text/html>]

The generated document.

[View source]


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

public String run_stats(dir, force = false)

Runs the report generation. If a report already exists, it wont be generated a second time, unless forced explicitly.

Meta Tags

Parameters:

[String] dir

The logfile directory of the report.

[true, false] force

If set to true, the report gets created unconditionally.

Returns:

[String]

The contents of #{dir}/report.html

[View source]


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

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

public undefined zip(dir, filename)

Creates a zip file out of a directory.

Meta Tags

Parameters:

[String] dir

The directories name.

[String] filename

The output filename.

Returns:

[undefined]

unspecified

[View source]


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

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
Generated on Tuesday, July 21 2009 at 11:24:31 PM by YARD 0.2.3.2 (ruby-1.9.1).