traffiction 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +36 -0
- data/Rakefile +2 -0
- data/bin/traffiction +32 -0
- data/lib/traffiction.rb +60 -0
- data/lib/traffiction/version.rb +3 -0
- data/traffiction.gemspec +25 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a3843f7b8bc6cba2375f23c92d91209f35feb945
|
4
|
+
data.tar.gz: 733387c16f219ef1e682db312705f251e9324d4c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3759b22c3da1359b8f504386bd52f450e1fd2b4b2a6f1db0ea12067df72e51f586101772cf38f3233838a8bd470b475762dd501860c6e3565b7443c0474e3c56
|
7
|
+
data.tar.gz: 81bb59b893370b2b196f058992044ac21237ae9f79096251823f44d15e56a40ca19548898851fe74e13a32929e41a9b98f49249992c4ce924b077ff51b064929
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Forrest Fleming
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Traffiction
|
2
|
+
|
3
|
+
This command-line tool simply generates traffic for a specific URL. It was
|
4
|
+
created for Oversee.net's QA team to simulate traffic in QA and staging
|
5
|
+
environments in order to test our concurrent-user-tracking functionality.
|
6
|
+
|
7
|
+
This is a simple wrapper - it's not intended for programmatic use, although
|
8
|
+
nothing's stopping anyone from using Traffiction as a regular old Ruby module.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
```
|
13
|
+
$ gem install traffiction
|
14
|
+
```
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
```
|
19
|
+
% traffiction
|
20
|
+
-v, --verbose Verbose output
|
21
|
+
-p, --port PORT Port
|
22
|
+
-c, --count COUNT Number of visits to perform
|
23
|
+
-t, --threads THREADS Number of threads to use
|
24
|
+
-h, --help Display this screen
|
25
|
+
```
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
1. Fork it ( https://github.com/oversee-ffleming/traffiction/fork )
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create a new Pull Request
|
34
|
+
|
35
|
+
## Todo
|
36
|
+
* Tests
|
data/Rakefile
ADDED
data/bin/traffiction
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'traffiction'
|
3
|
+
require 'optparse'
|
4
|
+
def opts_from_cli
|
5
|
+
options = {}
|
6
|
+
opt_parser = OptionParser.new do |opts|
|
7
|
+
opts.banner = "#{$0} [options] url"
|
8
|
+
opts.on('-v', '--verbose', 'Verbose output') { options[:verbose] = true }
|
9
|
+
opts.on('-p PORT', '--port PORT', 'Port') { |port| options[:port] = port }
|
10
|
+
opts.on('-c COUNT', '--count COUNT', 'Number of visits to perform') { |count| options[:count] = count.to_i }
|
11
|
+
opts.on('-t THREADS', '--threads THREADS', 'Number of threads to use') { |threads| options[:threads] = threads.to_i }
|
12
|
+
opts.on('-h', '--help', 'Display this screen') { puts opts ; exit }
|
13
|
+
end
|
14
|
+
opt_parser.parse!
|
15
|
+
|
16
|
+
options[:count] = 5 if options[:count].to_i == 0
|
17
|
+
options[:threads] = 4 if options[:threads].to_i == 0
|
18
|
+
options[:url] = ARGV.pop
|
19
|
+
abort opt_parser.to_s if options[:url].nil?
|
20
|
+
|
21
|
+
options[:url] = options[:url].sub('http://', '')
|
22
|
+
if options[:url] =~ /^(.*?):(\d+)$/
|
23
|
+
options[:url] = $1
|
24
|
+
options[:port] = $2
|
25
|
+
else
|
26
|
+
options[:port] = 80
|
27
|
+
end
|
28
|
+
puts options.inspect if options[:verbose]
|
29
|
+
options
|
30
|
+
end
|
31
|
+
|
32
|
+
Traffiction.generate(opts_from_cli)
|
data/lib/traffiction.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require "traffiction/version"
|
2
|
+
require 'ruby-progressbar'
|
3
|
+
require 'httparty'
|
4
|
+
module Traffiction
|
5
|
+
class << self
|
6
|
+
# Generates threads, runs the sweep, and returns
|
7
|
+
# @param [Hash] Parameters hash of the following format:
|
8
|
+
# threads: Fixnum, number of threads to create
|
9
|
+
# count: Fixnum, number of times to visit the site
|
10
|
+
# url: String, url to visit
|
11
|
+
# port: Fixnum, port
|
12
|
+
# verbose: Boolean, whether to print verbose output
|
13
|
+
# @return nil
|
14
|
+
def generate(options={})
|
15
|
+
@options = options
|
16
|
+
puts "#{visits_array.count} threads will be created with visit distribution #{visits_array}" if options[:verbose]
|
17
|
+
visits_array.each do |times|
|
18
|
+
threads.push Thread.new { visit("#{options[:url]}:#{options[:port]}", times) }
|
19
|
+
end
|
20
|
+
begin
|
21
|
+
threads.each { |t| t.join }
|
22
|
+
rescue => e
|
23
|
+
abort "#{e}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
attr_reader :options
|
29
|
+
|
30
|
+
def progress_bar
|
31
|
+
@progress_bar ||= ProgressBar.create(
|
32
|
+
title: "Visits",
|
33
|
+
total: options[:count],
|
34
|
+
format: '|%B| %E',
|
35
|
+
width: 20,
|
36
|
+
progress_mark: '='
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
def threads
|
41
|
+
@threads ||= []
|
42
|
+
end
|
43
|
+
|
44
|
+
def visit(url_string, times=1)
|
45
|
+
(1..times).map do
|
46
|
+
progress_bar.increment
|
47
|
+
HTTParty.get("http://#{url_string}")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def visits_array
|
52
|
+
return @visits_array unless @visits_array.nil?
|
53
|
+
ret = Array.new(options[:threads], 0)
|
54
|
+
(1..options[:count]).map do |i|
|
55
|
+
ret[i % options[:threads]] += 1
|
56
|
+
end
|
57
|
+
@visits_array = ret.select { |el| el > 0 }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/traffiction.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'traffiction/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "traffiction"
|
8
|
+
spec.version = Traffiction::VERSION
|
9
|
+
spec.authors = ['Forrest Fleming']
|
10
|
+
spec.email = ['ffleming@oversee.net']
|
11
|
+
spec.summary = %q(Hits a url a specified number of times. It's like a curl loop, but faster.)
|
12
|
+
spec.description = %q(Performs an HTTParty::get request in a reasonably threaded manner.) <<
|
13
|
+
%q(Primarily useful for manipulating concurrent users displays on staging environments)
|
14
|
+
spec.homepage = 'https://github.com/oversee-ffleming/traffiction'
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
23
|
+
spec.add_runtime_dependency 'ruby-progressbar', '~> 1.7'
|
24
|
+
spec.add_runtime_dependency 'httparty', '~> 0.13'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: traffiction
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Forrest Fleming
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ruby-progressbar
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: httparty
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.13'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.13'
|
55
|
+
description: Performs an HTTParty::get request in a reasonably threaded manner.Primarily
|
56
|
+
useful for manipulating concurrent users displays on staging environments
|
57
|
+
email:
|
58
|
+
- ffleming@oversee.net
|
59
|
+
executables:
|
60
|
+
- traffiction
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/traffiction
|
70
|
+
- lib/traffiction.rb
|
71
|
+
- lib/traffiction/version.rb
|
72
|
+
- traffiction.gemspec
|
73
|
+
homepage: https://github.com/oversee-ffleming/traffiction
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.2.2
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Hits a url a specified number of times. It's like a curl loop, but faster.
|
97
|
+
test_files: []
|