webmeter 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ .rspec
5
+ Gemfile.lock
6
+ nbproject
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in webmeter.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Adrian Dulić
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,4 @@
1
+ Website benchmark tool
2
+
3
+ Example:
4
+ ./bin/webmeter example.com
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/access.log ADDED
@@ -0,0 +1 @@
1
+ 127.0.0.1 - - [08/Feb/2011:06:33:36 +0100] "GET / HTTP/1.0" 200 1024 "-" "Mozilla"
data/bin/webmeter ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
3
+
4
+ require 'webmeter/cli'
5
+ Webmeter::CLI.execute
data/lib/webmeter.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'webmeter/benchmark'
2
+ require 'webmeter/parser'
3
+ require 'webmeter/worker'
@@ -0,0 +1,31 @@
1
+ module Webmeter
2
+ class Benchmark
3
+ def self.bench(params)
4
+ params[:paths] ||= Parser.new(params[:file]).parse || ["/"]
5
+ params[:workers] ||= 25
6
+ params[:address] ||= "example.com"
7
+
8
+ if params[:limit]
9
+ params[:paths] = params[:paths][0, params[:limit]]
10
+ end
11
+
12
+ workers = []
13
+ params[:workers].times { |w|
14
+ worker = Worker.new(params[:address], params[:paths])
15
+ worker.user_agent = w
16
+ workers << worker.run
17
+ }
18
+
19
+ start = Time.now
20
+ workers.each { |w| w.join }
21
+ time = (Time.now - start).to_f
22
+
23
+ requests = params[:paths].size * params[:workers]
24
+
25
+ puts "Webmeter #{params[:address]}"
26
+ puts "Time taken for test #{time}"
27
+ puts "Requests #{requests}"
28
+ puts "Req/sec #{requests/time}"
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,45 @@
1
+ require 'webmeter'
2
+ require 'optparse'
3
+
4
+ module Webmeter
5
+ class CLI
6
+ attr_accessor :options
7
+
8
+ def self.execute(options = nil)
9
+ new(options || ARGV)
10
+ end
11
+
12
+ def initialize(options)
13
+ @options = options
14
+ execute
15
+ end
16
+
17
+ def execute
18
+ params = {}
19
+ optparse = OptionParser.new do |opts|
20
+ opts.on('-h', '--help', 'Display this screen') do
21
+ puts opts
22
+ exit
23
+ end
24
+ params[:address] = "www.example.com"
25
+ opts.on('-a', '--address <domain>', String, 'Website address') do |address|
26
+ params[:address] = address
27
+ end
28
+ params[:workers] = 1
29
+ opts.on('-w', '--workers <number>', Integer, 'Number of workers') do |workers|
30
+ params[:workers] = workers
31
+ end
32
+ params[:file] = "access.log"
33
+ opts.on('-f', '--file <path>', String, 'Log file') do |file|
34
+ params[:file] = file
35
+ end
36
+ params[:limit] = nil
37
+ opts.on('-l', '--limit <number>', Integer, 'Limit requests') do |limit|
38
+ params[:limit] = limit
39
+ end
40
+ end
41
+ optparse.parse!
42
+ Benchmark.bench(params)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,17 @@
1
+ module Webmeter
2
+ class Parser
3
+ def initialize(filename)
4
+ @filename = filename
5
+ end
6
+
7
+ def parse
8
+ file = File.new(@filename)
9
+ matches = []
10
+ file.each { |log|
11
+ match = log.match(/GET (.*?) HTTP/)
12
+ matches << match[1] if not match.nil?
13
+ }
14
+ matches.map(&:strip)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module Webmeter
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ require 'net/http'
2
+
3
+ module Webmeter
4
+ class Worker
5
+ attr_accessor :user_agent, :host, :paths
6
+
7
+ def initialize(host, paths)
8
+ @host = host
9
+ @paths = paths
10
+ end
11
+
12
+ def work
13
+ @paths.each { |path|
14
+ req = Net::HTTP::Get.new(path, {'User-Agent' => "Webmeter/worker-#{@user_agent}"})
15
+ req.basic_auth('user', 'password')
16
+ res = Net::HTTP.new(@host).start { |http| http.request(req) }
17
+ }
18
+ end
19
+
20
+ def run
21
+ Thread.new { work }
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,10 @@
1
+ require 'webmeter/cli'
2
+
3
+ describe "Webmeter" do
4
+ context "CLI" do
5
+ it "should parse options" do
6
+ cli = Webmeter::CLI.execute(["-a", "test.com"])
7
+ cli.options.should == ["-a", "test.com"]
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'rspec'
2
+ require 'webmeter'
3
+
4
+ Rspec.configure do |c|
5
+ c.mock_with :rspec
6
+ end
7
+
data/webmeter.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "webmeter/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "webmeter"
7
+ s.version = Webmeter::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Adrian Dulić"]
10
+ s.email = ["adulic@gmail.com"]
11
+ s.homepage = "http://github.com/adriandulic/webmeter"
12
+ s.summary = %q{Website benchmark tool}
13
+ s.description = %q{Simple website benchmark tool written in ruby}
14
+ s.executables = ["messenger"]
15
+ s.extra_rdoc_files = ["LICENSE", "README.markdown"]
16
+ s.required_rubygems_version = ">= 1.3.6"
17
+ s.rubyforge_project = "webmeter"
18
+ s.add_development_dependency "bundler", "1.0.10"
19
+ s.add_development_dependency "rspec", "2.5.0"
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: webmeter
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - "Adrian Duli\xC4\x87"
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-08 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: bundler
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - "="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 1
32
+ - 0
33
+ - 10
34
+ version: 1.0.10
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - "="
44
+ - !ruby/object:Gem::Version
45
+ hash: 27
46
+ segments:
47
+ - 2
48
+ - 5
49
+ - 0
50
+ version: 2.5.0
51
+ type: :development
52
+ version_requirements: *id002
53
+ description: Simple website benchmark tool written in ruby
54
+ email:
55
+ - adulic@gmail.com
56
+ executables:
57
+ - webmeter
58
+ extensions: []
59
+
60
+ extra_rdoc_files:
61
+ - LICENSE
62
+ - README.markdown
63
+ files:
64
+ - .gitignore
65
+ - Gemfile
66
+ - LICENSE
67
+ - README.markdown
68
+ - Rakefile
69
+ - access.log
70
+ - bin/webmeter
71
+ - lib/webmeter.rb
72
+ - lib/webmeter/benchmark.rb
73
+ - lib/webmeter/cli.rb
74
+ - lib/webmeter/parser.rb
75
+ - lib/webmeter/version.rb
76
+ - lib/webmeter/worker.rb
77
+ - spec/lib/cli_spec.rb
78
+ - spec/spec_helper.rb
79
+ - webmeter.gemspec
80
+ has_rdoc: true
81
+ homepage: http://github.com/adriandulic/webmeter
82
+ licenses: []
83
+
84
+ post_install_message:
85
+ rdoc_options: []
86
+
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
+ hash: 3
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 23
104
+ segments:
105
+ - 1
106
+ - 3
107
+ - 6
108
+ version: 1.3.6
109
+ requirements: []
110
+
111
+ rubyforge_project: webmeter
112
+ rubygems_version: 1.5.0
113
+ signing_key:
114
+ specification_version: 3
115
+ summary: Website benchmark tool
116
+ test_files: []
117
+