-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
36 lines (31 loc) · 827 Bytes
/
app.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
from flask import Flask, jsonify
import os
import sys
import shutil
app = Flask(__name__)
@app.route("/disk_space", methods=["GET"])
@app.route("/", methods=["GET"])
def disk_space():
total, used, free = shutil.disk_usage("/")
headers = {"Access-Control-Allow-Origin": "*"}
# Calculage % used:
disk_percentage_used = int((used / total) * 100)
return (
jsonify(
{
"total": total,
"used": used,
"free": free,
"use": f"{disk_percentage_used}%",
} # noqa: E501
),
200,
headers,
)
if __name__ == "__main__":
port = (
int(sys.argv[1])
if len(sys.argv) > 1
else int(os.getenv("DISK_USAGE_ENDPOINT_PORT", 5000))
)
app.run(host="0.0.0.0", port=port)