autoperf 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'rake'
7
+ gem 'pry'
8
+ gem 'pry-doc'
9
+ end
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Autoperf (w/ HTTPerf.rb)
2
+
3
+ ### See: [rubyops.net/gems/autoperf](http://www.rubyops.net/gems/autoperf)
data/bin/autoperf ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'autoperf')
4
+
5
+ trap("INT") {
6
+ puts "Terminating tests."
7
+ Process.exit
8
+ }
9
+
10
+ conf = ""
11
+ options = OptionParser.new do |opts|
12
+ opts.banner = "Usage: autoperf.rb [-c config]"
13
+
14
+ opts.on("-c", "--config [STRING]", String, "configuration file") do |c|
15
+ conf = c
16
+ end
17
+ end
18
+
19
+ options.parse!
20
+ if conf.empty?
21
+ puts options
22
+ exit 1
23
+ end
24
+
25
+ autoperf = Autoperf.new(conf)
26
+ autoperf.run()
27
+ autoperf.display.print
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'replay_log')
3
+ progname = File.basename($0)
4
+
5
+ if ARGV.size < 3
6
+ puts "Usage: ruby #{progname} 'match' 'substitute' 'http_server' file1 [file2 [file3]] > output_file"
7
+ puts "Usage: cat logfile | ruby #{progname} 'match' 'substitute' 'http_server' > output_file"
8
+ puts
9
+ puts "Example: cat /var/log/access_log | ruby #{progname} '/app' '/' nginx > replay_log"
10
+ puts "Example: cat /var/log/access_log | ruby #{progname} '' '' apache > replay_log"
11
+ exit
12
+ end
13
+
14
+ match = ARGV.shift
15
+ sub = ARGV.shift
16
+ type = ARGV.shift
17
+
18
+ ARGF.each { |line| ReplayLog.parse(line, match, sub, type) }
data/lib/autoperf.rb ADDED
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'yaml'
3
+ require 'httperf'
4
+ require 'json'
5
+ require 'autoperf/display'
6
+
7
+ class Autoperf
8
+ def initialize(config_file, opts = {})
9
+ @conf = parse_config(config_file).merge(opts)
10
+ @perf = HTTPerf.new(@conf)
11
+ @perf.parse = true
12
+ @perf.tee = true if @tee
13
+ end
14
+
15
+ def parse_config(config_file)
16
+ raise Errno::EACCES, "#{config_file} is not readable" unless File.readable?(config_file)
17
+ config = YAML::load(File.open(config_file, 'r'))
18
+ @rates = {
19
+ :low_rate => config.delete('low_rate'),
20
+ :high_rate => config.delete('high_rate'),
21
+ :rate_step => config.delete('rate_step')
22
+ }
23
+ @cols = config.delete('display_columns') if config.has_key?('display_columns')
24
+ @tee = config.delete('tee')||false
25
+ return config
26
+ end
27
+
28
+ def run report=nil
29
+ @results = {}
30
+ (@rates[:low_rate].to_i..@rates[:high_rate].to_i).step(@rates[:rate_step].to_i) do |rate|
31
+ @perf.update_option("rate", rate.to_s)
32
+ @results[rate] = @perf.run
33
+ end
34
+ return @results
35
+ end
36
+
37
+ def display
38
+ @results ||= {}
39
+ if @cols
40
+ Autoperf::Display.new(@results, @cols)
41
+ else
42
+ Autoperf::Display.new(@results)
43
+ end
44
+ end
45
+
46
+ def to_s
47
+ display.to_s
48
+ end
49
+
50
+ def to_json
51
+ @results ||= {}
52
+ @results.to_json
53
+ end
54
+ end
@@ -0,0 +1,40 @@
1
+ require 'ruport'
2
+ class Autoperf
3
+ class Display
4
+ def initialize results, report=nil
5
+ @table = if report.kind_of?(Array)
6
+ table_from_array(report)
7
+ elsif report.kind_of?(Ruport::Data::Table)
8
+ report
9
+ else
10
+ # ignore input and use defaults
11
+ table_from_array([
12
+ :rate,
13
+ :connection_rate_per_sec,
14
+ :request_rate_per_sec,
15
+ :connection_time_avg,
16
+ :errors_total,
17
+ :reply_status_5xx,
18
+ :net_io_kb_sec
19
+ ])
20
+ end
21
+ results.each do |rate, result|
22
+ result.merge!(:rate => rate) if @table.column_names.include?(:rate)
23
+ @table << result
24
+ end
25
+ end
26
+
27
+ def to_s
28
+ @table.to_s
29
+ end
30
+
31
+ def print
32
+ puts to_s
33
+ end
34
+
35
+ def table_from_array report
36
+ Table(:column_names => report)
37
+ end
38
+ end
39
+ end
40
+
@@ -0,0 +1,3 @@
1
+ class Autoperf
2
+ VERSION = "1.0.4"
3
+ end
data/lib/replay_log.rb ADDED
@@ -0,0 +1,40 @@
1
+ module ReplayLog
2
+ def self.parse input, match='', sub='', type=:nginx
3
+ result = ""
4
+ if input.respond_to?(:each)
5
+ input.each do |line|
6
+ line_result = send("parse_line_#{type}".to_sym, line, match, sub)
7
+ print line_result
8
+ result << line_result
9
+ end
10
+ else
11
+ result = send("parse_line_#{type}".to_sym, input, match, sub)
12
+ print result
13
+ end
14
+ return result
15
+ end
16
+
17
+ def self.parse_line_apache line, match='', sub=''
18
+ parse_line(line, match, sub)
19
+ end
20
+
21
+ def self.parse_line_nginx line, match='', sub=''
22
+ parse_line(line, match, sub)
23
+ end
24
+
25
+ def self.parse_line line, match='', sub=''
26
+ request = line.split('"')[1]
27
+ return if request.nil?
28
+
29
+ uri = request.split[1]
30
+ return if uri.nil?
31
+
32
+ begin
33
+ uri[match] = sub unless match.empty?
34
+ rescue IndexError
35
+ # simply output line that don't contain the 'replace' string
36
+ ensure
37
+ return uri.chomp + "\0"
38
+ end
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: autoperf
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.4
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Joshua Mervine
9
+ - Ilya Grigorik
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-04-15 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: httperfrb
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: 0.3.11
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: 0.3.11
47
+ - !ruby/object:Gem::Dependency
48
+ name: ruport
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ description: Autoperf is a ruby driver for httperf, designed to help you automate
64
+ load and performance testing of any web application - for a single end point, or
65
+ through log replay.
66
+ email:
67
+ - joshua@mervine.net
68
+ - excluded
69
+ executables:
70
+ - autoperf
71
+ - make_replay_log
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - lib/autoperf/display.rb
76
+ - lib/autoperf/version.rb
77
+ - lib/replay_log.rb
78
+ - lib/autoperf.rb
79
+ - bin/autoperf
80
+ - bin/make_replay_log
81
+ - README.md
82
+ - Gemfile
83
+ homepage: http://www.rubyops.net/gems/autoperf
84
+ licenses: []
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 1.8.24
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: Autoperf (w/ HTTPerf.rb)
107
+ test_files: []
108
+ has_rdoc: