Update app.py
Browse files
app.py
CHANGED
|
@@ -1,38 +1,42 @@
|
|
| 1 |
-
import
|
| 2 |
-
import
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
def
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
| 30 |
return response
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import random
|
| 3 |
+
import time
|
| 4 |
+
from datetime import datetime
|
| 5 |
+
|
| 6 |
+
from flask import Flask, Response, render_template, stream_with_context
|
| 7 |
+
|
| 8 |
+
app = Flask(__name__)
|
| 9 |
+
random.seed() # Initialize the random number generator
|
| 10 |
+
global reqs
|
| 11 |
+
reqs = 0
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
@app.route('/dstat')
|
| 15 |
+
def index():
|
| 16 |
+
with open("index.html", "r") as f:
|
| 17 |
+
html = f.read()
|
| 18 |
+
return html
|
| 19 |
+
|
| 20 |
+
@app.route('/chart-data')
|
| 21 |
+
def chart_data():
|
| 22 |
+
def generate_random_data():
|
| 23 |
+
while True:
|
| 24 |
+
json_data = json.dumps(
|
| 25 |
+
{'time': datetime.now().strftime('%M:%S'), 'value': reqs})
|
| 26 |
+
yield f"data:{json_data}\n\n"
|
| 27 |
+
time.sleep(1)
|
| 28 |
+
|
| 29 |
+
response = Response(stream_with_context(generate_random_data()), mimetype="text/event-stream")
|
| 30 |
+
response.headers["Cache-Control"] = "no-cache"
|
| 31 |
+
response.headers["X-Accel-Buffering"] = "no"
|
| 32 |
return response
|
| 33 |
|
| 34 |
+
@app.route("/attack")
|
| 35 |
+
def attack():
|
| 36 |
+
global reqs
|
| 37 |
+
reqs = reqs + 1
|
| 38 |
+
return "200"
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
if __name__ == '__main__':
|
| 42 |
+
app.run(debug=True, threaded=True, host="0.0.0.0", port=80)
|