Permalink
Browse files

Merge remote-tracking branch 'upstream/master'

  • Loading branch information...
calebfornari committed Apr 15, 2013
2 parents 58b3c42 + 877458d commit 320384be769a8bdf96e61454de5b9fa88104565e
Showing with 42 additions and 16 deletions.
  1. +22 −6 beeswithmachineguns/bees.py
  2. +16 −6 beeswithmachineguns/main.py
  3. +2 −2 requirements.txt
  4. +2 −2 setup.py
@@ -202,12 +202,17 @@ def _attack(params):
print 'Bee %i is firing his machine gun. Bang bang!' % params['i']
- params['header_string'] = '';
+ options = ''
if params['headers'] is not '':
for h in params['headers'].split(';'):
- params['header_string'] += ' -H ' + h
-
- stdin, stdout, stderr = client.exec_command('ab -r -n %(num_requests)s -c %(concurrent_requests)s -C "sessionid=NotARealSessionID" %(header_string)s "%(url)s"' % params)
+ options += ' -H "%s"' % h
+
+ if params['post_file']:
+ os.system("scp -q -o 'StrictHostKeyChecking=no' %s %s@%s:/tmp/honeycomb" % (params['post_file'], params['username'], params['instance_name']))
+ options += ' -k -T "%(mime_type)s; charset=UTF-8" -p /tmp/honeycomb' % params
+
+ benchmark_command = 'ab -r -n %(num_requests)s -c %(concurrent_requests)s -C "sessionid=NotARealSessionID" %(options) "%(url)s"' % params
+ stdin, stdout, stderr = client.exec_command(benchmark_command)
response = {}
@@ -219,12 +224,14 @@ def _attack(params):
return None
requests_per_second_search = re.search('Requests\ per\ second:\s+([0-9.]+)\ \[#\/sec\]\ \(mean\)', ab_results)
+ failed_requests = re.search('Failed\ requests:\s+([0-9.]+)', ab_results)
fifty_percent_search = re.search('\s+50\%\s+([0-9]+)', ab_results)
ninety_percent_search = re.search('\s+90\%\s+([0-9]+)', ab_results)
complete_requests_search = re.search('Complete\ requests:\s+([0-9]+)', ab_results)
response['ms_per_request'] = float(ms_per_request_search.group(1))
response['requests_per_second'] = float(requests_per_second_search.group(1))
+ response['failed_requests'] = float(failed_requests.group(1))
response['fifty_percent'] = float(fifty_percent_search.group(1))
response['ninety_percent'] = float(ninety_percent_search.group(1))
response['complete_requests'] = float(complete_requests_search.group(1))
@@ -264,6 +271,10 @@ def _print_results(results):
total_complete_requests = sum(complete_results)
print ' Complete requests:\t\t%i' % total_complete_requests
+ complete_results = [r['failed_requests'] for r in complete_bees]
+ total_failed_requests = sum(complete_results)
+ print ' Failed requests:\t\t%i' % total_failed_requests
+
complete_results = [r['requests_per_second'] for r in complete_bees]
mean_requests = sum(complete_results)
print ' Requests per second:\t%f [#/sec] (mean)' % mean_requests
@@ -291,7 +302,7 @@ def _print_results(results):
else:
print 'Mission Assessment: Swarm annihilated target.'
-def attack(url, n, c, headers):
+def attack(url, n, c, **options):
"""
Test the root url of this site.
"""
@@ -322,6 +333,9 @@ def attack(url, n, c, headers):
if c < instance_count:
print 'bees: error: the number of concurrent requests must be at least %d (num. instances)' % instance_count
return
+ if n < c:
+ print 'bees: error: the number of concurrent requests (%d) must be at most the same as number of requests (%d)' % (c, n)
+ return
requests_per_instance = int(float(n) / instance_count)
connections_per_instance = int(float(c) / instance_count)
@@ -340,7 +354,9 @@ def attack(url, n, c, headers):
'num_requests': requests_per_instance,
'username': username,
'key_name': key_name,
- 'headers': headers,
+ 'headers': options.get('headers', ''),
+ 'post_file': options.get('post_file'),
+ 'mime_type': options.get('mime_type', ''),
})
print 'Stinging URL so it will be cached for the attack.'
@@ -48,12 +48,12 @@ def parse_options():
report Report the status of the load testing servers.
""")
- up_group = OptionGroup(parser, "up",
+ up_group = OptionGroup(parser, "up",
"""In order to spin up new servers you will need to specify at least the -k command, which is the name of the EC2 keypair to use for creating and connecting to the new servers. The bees will expect to find a .pem file with this name in ~/.ssh/.""")
# Required
up_group.add_option('-k', '--key', metavar="KEY", nargs=1,
- action='store', dest='key', type='string',
+ action='store', dest='key', type='string',
help="The ssh key pair name to use to connect to the new servers.")
up_group.add_option('-s', '--servers', metavar="SERVERS", nargs=1,
@@ -80,14 +80,19 @@ def parse_options():
parser.add_option_group(up_group)
- attack_group = OptionGroup(parser, "attack",
+ attack_group = OptionGroup(parser, "attack",
"""Beginning an attack requires only that you specify the -u option with the URL you wish to target.""")
# Required
attack_group.add_option('-u', '--url', metavar="URL", nargs=1,
action='store', dest='url', type='string',
help="URL of the target to attack.")
-
+ attack_group.add_option('-p', '--post-file', metavar="POST_FILE", nargs=1,
+ action='store', dest='post_file', type='string', default=False,
+ help="The POST file to deliver with the bee's payload.")
+ attack_group.add_option('-m', '--mime-type', metavar="MIME_TYPE", nargs=1,
+ action='store', dest='mime_type', type='string', default='text/plain',
+ help="The MIME type to send with the request.")
attack_group.add_option('-n', '--number', metavar="NUMBER", nargs=1,
action='store', dest='number', type='int', default=1000,
help="The number of total connections to make to the target (default: 1000).")
@@ -126,7 +131,13 @@ def parse_options():
if not parsed.path:
parser.error('It appears your URL lacks a trailing slash, this will disorient the bees. Please try again with a trailing slash.')
- bees.attack(options.url, options.number, options.concurrent, options.headers)
+ additional_options = dict(
+ headers=options.headers,
+ post_file=options.post_file,
+ mime_type=options.mime_type,
+ )
+
+ bees.attack(options.url, options.number, options.concurrent, **additional_options)
elif command == 'down':
bees.down()
elif command == 'report':
@@ -135,4 +146,3 @@ def parse_options():
def main():
parse_options()
-
View
@@ -1,2 +1,2 @@
-boto==2.7.0
-paramiko==1.7.7.1
+boto==2.8.0
+paramiko==1.10.1
View
@@ -12,8 +12,8 @@
packages=['beeswithmachineguns'],
scripts=['bees'],
install_requires=[
- 'boto==2.7.0',
- 'paramiko==1.7.7.1'
+ 'boto==2.8.0',
+ 'paramiko==1.10.1'
],
classifiers=[
'Development Status :: 4 - Beta',

0 comments on commit 320384b

Please sign in to comment.