siege_siege 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5132d5648931cb1f5c1fca9dd34de1eadbeb04d6
4
+ data.tar.gz: 40e8d21f5127dfbee7b5e8aeca7a0687aba4b6f2
5
+ SHA512:
6
+ metadata.gz: b73732098ff9da13441255b7a3d1e460f651c2d01420bbb4dab6fe56e49b2f6b5dedb995e4d7585986ddf984637d3230dd133ee8c531798b375424f3f58a5073
7
+ data.tar.gz: 94d18ad5ec1f91f00fcddc8e808ca4cdd4cf609161970c17d87c51f8a3de02f8d9c8f300de45e3e0fd035e603c971c8bd460eabc67488e70cfeff27aa8c43bf9
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in siege_siege.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 mmmpa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # SiegeSiege
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/siege_siege`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'siege_siege'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install siege_siege
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/siege_siege.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "siege_siege"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,51 @@
1
+ module SiegeSiege
2
+ class Siege
3
+ CONFIGURATIONS = %w(
4
+ verbose
5
+ quiet
6
+ gmethod
7
+ csv
8
+ timestamp
9
+ fullurl
10
+ display-id
11
+ limit
12
+ show-logfile
13
+ logging
14
+ logfile
15
+ protocol
16
+ chunked
17
+ cache
18
+ connection
19
+ concurrent
20
+ time
21
+ reps
22
+ file
23
+ url
24
+ delay
25
+ timeout
26
+ expire-session
27
+ cookies
28
+ failures
29
+ internet
30
+ benchmark
31
+ user-agent
32
+ accept-encoding
33
+ url-escaping
34
+ spinner
35
+ login
36
+ login-url
37
+ ftp-login
38
+ unique
39
+ ssl-cert
40
+ ssl-key
41
+ ssl-timeout
42
+ ssl-ciphers
43
+ proxy-host
44
+ proxy-port
45
+ proxy-login
46
+ follow-location
47
+ zero-data-ok
48
+ )
49
+
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ module SiegeSiege
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,210 @@
1
+ require 'siege_siege/version'
2
+ require 'open3'
3
+ require 'tempfile'
4
+ require 'csv'
5
+ require 'pp'
6
+ require 'active_support'
7
+ require 'active_support/core_ext'
8
+
9
+
10
+ module SiegeSiege
11
+ class Runner
12
+ attr_accessor :conf, :urls
13
+
14
+ def initialize(raw_configuration = {})
15
+ @conf = Tempfile.open
16
+ @urls = Tempfile.open
17
+ @command = nil
18
+
19
+ Configuration.new(
20
+ {
21
+ concurrent: 1,
22
+ time: 10,
23
+ reps: 1
24
+ }.merge!(raw_configuration).merge!(
25
+ verbose: true,
26
+ rc: @conf.path,
27
+ csv: true,
28
+ display_id: true,
29
+ quiet: false,
30
+ file: raw_configuration[:url] ? nil : @urls.path
31
+ )
32
+ ).tap do |conf|
33
+ File.write(@conf, conf.rc)
34
+ File.write(@urls, conf.urls)
35
+ @command = "siege #{conf.options}"
36
+ end
37
+ puts @command
38
+ end
39
+
40
+ def run
41
+ _, stdout, stderr = Open3.popen3(@command)
42
+ Result.new(stdout.read, stderr.read)
43
+ end
44
+ end
45
+
46
+ class URL < Struct.new(:url, :method, :parameter)
47
+ def initialize(*)
48
+ super
49
+
50
+ raise RequireURL unless url
51
+
52
+ self.method ||= :get
53
+ self.parameter ||= {}
54
+ end
55
+
56
+ def to_siege_url
57
+ if method && method.to_s.downcase == 'post'
58
+ [url, 'POST', parameter.to_param]
59
+ else
60
+ url
61
+ end
62
+ end
63
+
64
+ class RequireURL < StandardError
65
+
66
+ end
67
+ end
68
+
69
+ class Result
70
+ def initialize(raw, raw_result)
71
+ @raw = raw
72
+ puts @raw_result = raw_result
73
+ end
74
+
75
+ def raw_log
76
+ @stored_logs ||= begin
77
+ @raw
78
+ .gsub(/\e.+?m/, '')
79
+ .gsub('[', '')
80
+ .gsub(']', '')
81
+ .gsub(' ', '')
82
+ .split("\n").map { |line| LineLog.new(*line.split(',')) rescue nil }
83
+ .compact
84
+ end
85
+ end
86
+
87
+ def average_log
88
+ @stored_average_log ||= raw_log.group_by { |line| line.id }.map { |id, group|
89
+ count = group.size
90
+ average = (group.inject(0) { |a, log| a + log.secs } / count).round(3)
91
+ head = group.first
92
+ AverageLog.new(id, head.url, count, average)
93
+ }
94
+ end
95
+ end
96
+
97
+ class AverageLog < Struct.new(:id, :url, :count, :secs)
98
+
99
+ end
100
+
101
+ class LineLog < Struct.new(:week_day, :date, :protocol, :status, :secs, :bytes, :url, :id, :date2)
102
+ def initialize(*)
103
+ super
104
+
105
+ raise InvalidLine unless date2
106
+
107
+ self.secs = secs.to_f
108
+ self.bytes = bytes.to_i
109
+ self.id = id.to_i
110
+ end
111
+
112
+ class InvalidLine < StandardError
113
+
114
+ end
115
+ end
116
+
117
+ class Configuration
118
+ OPTION_MAP = {
119
+ verbose: 'v',
120
+ concurrent: 'c',
121
+ internet: 'i',
122
+ time: 't',
123
+ reps: 'r',
124
+ log: 'l',
125
+ mark: 'm',
126
+ delay: 'd',
127
+ header: 'H',
128
+ user_agent: 'A',
129
+ content_type: 'T',
130
+ rc: 'R',
131
+ file: 'f',
132
+ url: ''
133
+ }
134
+
135
+ RC_MAP = {
136
+ verbose: true,
137
+ quiet: false,
138
+ gmethod: 'HEAD',
139
+ csv: false,
140
+ timestamp: true,
141
+ fullurl: true,
142
+ display_id: true,
143
+ limit: 255,
144
+ show_logfile: true,
145
+ logging: true,
146
+ logfile: nil,
147
+ protocol: 'HTTP/1.1',
148
+ chunked: true,
149
+ cache: false,
150
+ timeout: 2000,
151
+ expire_session: false,
152
+ cookies: false,
153
+ failures: 1024,
154
+ benchmark: true,
155
+ accept_encoding: 'gzip',
156
+ url_escaping: true,
157
+ spinner: false,
158
+ login: nil,
159
+ login_url: nil,
160
+ ftp_login: nil,
161
+ unique: true,
162
+ ssl_cert: nil,
163
+ ssl_key: nil,
164
+ ssl_timeout: nil,
165
+ ssl_ciphers: nil,
166
+ proxy_host: nil,
167
+ proxy_port: nil,
168
+ proxy_login: nil,
169
+ follow_location: true,
170
+ zero_data_ok: true
171
+ }
172
+
173
+ def initialize(configuration)
174
+ @configuration = configuration
175
+ end
176
+
177
+ def urls
178
+ Array(@configuration[:urls]).map { |url|
179
+ (URL === url ? url : URL.new(url)).to_siege_url
180
+ }.join("\n")
181
+ end
182
+
183
+ def rc
184
+ RC_MAP.inject('') do |a, (key, value)|
185
+ inserting = @configuration[key] || value
186
+ if inserting
187
+ a << "#{key.to_s.gsub('_', '-')} = #{inserting}\n"
188
+ else
189
+ a
190
+ end
191
+ end
192
+ end
193
+
194
+ def options
195
+ OPTION_MAP.inject([]) { |a, (key, value)|
196
+ inserting = @configuration[key]
197
+ case
198
+ when TrueClass === inserting, FalseClass === inserting
199
+ a << "-#{value}"
200
+ when inserting && key == :time
201
+ a << "-#{value} #{@configuration[key]}s"
202
+ when inserting
203
+ a << "-#{value} #{@configuration[key]}"
204
+ else
205
+ a
206
+ end
207
+ }.join(' ')
208
+ end
209
+ end
210
+ end
data/server.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'webrick'
2
+
3
+ @port = ENV['PORT'] || 3001
4
+ @host = ENV['HOST'] || '127.0.0.1'
5
+ @base = "http://#{@host}:#{@port}"
6
+
7
+ WEBrick::HTTPServer.new(
8
+ DocumentRoot: File.expand_path('./spec/fixtures/', __dir__),
9
+ BindAddress: @host,
10
+ Port: @port,
11
+ AccessLog: [],
12
+ Logger: WEBrick::Log::new("/dev/null", 7)
13
+ ).tap do |server|
14
+ Signal.trap(:INT) { server.shutdown }
15
+ server.start
16
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'siege_siege/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "siege_siege"
8
+ spec.version = SiegeSiege::VERSION
9
+ spec.authors = ["mmmpa"]
10
+ spec.email = ["mmmpa.mmmpa@gmail.com"]
11
+
12
+ spec.summary = %q{siege wrapper}
13
+ spec.description = %q{siege wrapper}
14
+ spec.homepage = "http://mmmpa.net"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'activesupport'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.11"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: siege_siege
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - mmmpa
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: siege wrapper
70
+ email:
71
+ - mmmpa.mmmpa@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - lib/siege_siege.rb
85
+ - lib/siege_siege/siege.rb
86
+ - lib/siege_siege/version.rb
87
+ - server.rb
88
+ - siege_siege.gemspec
89
+ homepage: http://mmmpa.net
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.5.1
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: siege wrapper
113
+ test_files: []
114
+ has_rdoc: