forked from cgbystrom/locust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.py
54 lines (44 loc) · 1.11 KB
/
web.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import bottle
import gevent
import locust
import json
from bottle import route, run, send_file
from gevent import wsgi
from stats import RequestStats
_locust = None
_hatch_rate = 1
_max = 1
@route('/public/:filename')
def static_file(filename):
send_file(filename, root='public')
@route('/')
def index():
send_file('index.html', root='public')
@route('/swarm')
def start():
locust.swarm(_locust, _hatch_rate, _max)
return {'message': 'Swarming started'}
@route('/stats/requests')
def request_stats():
stats = []
for s in RequestStats.requests.itervalues():
stats.append([
s.name,
s.num_requests(),
s.avg_response_time(),
s.min_response_time(),
s.max_response_time(),
s.reqs_per_sec()
])
return json.dumps(stats)
def start(locust, hatch_rate, max):
global _locust, _hatch_rate, _max
_locust = locust
_hatch_rate = hatch_rate
_max = max
app = bottle.default_app()
wsgi.WSGIServer(('', 8089), app).start()
bottle.debug(True)
if __name__ == '__main__':
start()
gevent.sleep(1000000)