forked from cloud-ark/kubeplus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
28 lines (21 loc) · 880 Bytes
/
app.py
File metadata and controls
28 lines (21 loc) · 880 Bytes
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
# Custom Hello World app
from flask import Flask
from prometheus_client import Counter, generate_latest, CONTENT_TYPE_LATEST
app = Flask(__name__)
# Prometheus metrics (counts requests to "/" and "/bye")
HELLO_REQUEST_COUNT = Counter("hello_requests_total", "Total requests to hello endpoint")
BYE_REQUEST_COUNT = Counter("bye_requests_total", "Total requests to bye endpoint")
@app.route("/")
def hello():
HELLO_REQUEST_COUNT.inc() # increment counter every time / is hit
return "Hello World, from Kubernetes!<br>"
@app.route("/bye")
def bye():
BYE_REQUEST_COUNT.inc() # increment counter every time /bye is hit
return "Bye, from Kubernetes!<br>"
# Prometheus metrics endpoint
@app.route("/metrics")
def metrics():
return generate_latest(), 200, {"Content-Type": CONTENT_TYPE_LATEST}
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)