-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
41 lines (31 loc) · 932 Bytes
/
api.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
from flask import Flask, request, send_file
from flask_prometheus import monitor
import socket
import time
app = Flask(__name__)
monitor(app, port=6001)
@app.route("/")
def index():
return "Hello world from k8s! Edition 1.8.2!!"
@app.route("/host")
def ip():
return socket.gethostname()
@app.route("/headers")
def hello():
return "<xmp>Headers:\n{}Remote Address:\n{}</xmp>".format(request.headers, request.remote_addr)
@app.route("/cpuload")
def cpuload():
till = time.time() + 20 # 20 seconds load
while (time.time() < till):
pr = 213123
pr * pr
pr = pr + 1
return "Worked for 20s, now tired...", 200
@app.route("/happy")
def phippy_happy():
return send_file("phippy_happy.png", mimetype="image/png")
@app.route("/scared")
def phippy_unhappy():
return send_file("phippy.png", mimetype="image/png")
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)