From d7bde5453399faa834565e67fa6178c69667c49a Mon Sep 17 00:00:00 2001 From: pvlasak <93707814+pvlasak@users.noreply.github.com> Date: Fri, 14 Jun 2024 12:45:34 +0200 Subject: [PATCH] Feature/disk space (#199) * new backend API to get disk info from psutil * Disk info div + disk space gauge div * styling for git disk space gauge * inital commit - jquery request to system-info endpoint * div disk_info created * get_system_info function is initiated once DOM is fully loaded. * styling for disk-gauge-bar added * get_system_info endpoint returns additionally an information about network, cpu_time and memory * new
for graphical output of system info * increased widht for disk-gauge-container * if condition testing an index of response and rendering an output within div for graphical output * div deleted --- v2realbot/main.py | 20 +++++++++++++++++++- v2realbot/static/index.html | 21 ++++++++++++++++++++- v2realbot/static/js/systeminfo.js | 31 +++++++++++++++++++++++++++++++ v2realbot/static/main.css | 21 +++++++++++++++++++++ 4 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 v2realbot/static/js/systeminfo.js diff --git a/v2realbot/main.py b/v2realbot/main.py index f9d9060..e880613 100644 --- a/v2realbot/main.py +++ b/v2realbot/main.py @@ -18,6 +18,7 @@ from fastapi.security import HTTPBasic, HTTPBasicCredentials from v2realbot.enums.enums import Env, Mode from typing import Annotated import os +import psutil import uvicorn import orjson from queue import Queue, Empty @@ -1025,7 +1026,24 @@ def get_metadata(model_name: str): # "last_modified": os.path.getmtime(model_path), # # ... other metadata fields ... # } - +@app.get("/system-info") +def get_system_info(): + """Get system info, e.g. disk free space, used percentage ... """ + disk_total = round(psutil.disk_usage('/').total / 1024**3, 1) + disk_used = round(psutil.disk_usage('/').used / 1024**3, 1) + disk_free = round(psutil.disk_usage('/').free / 1024**3, 1) + disk_used_percentage = round(psutil.disk_usage('/').percent, 1) + memory_total = round(psutil.virtual_memory().total / 1024**3, 1) + memory_perc = round(psutil.virtual_memory().percent, 1) + cpu_time_user = round(psutil.cpu_times().user,1) + cpu_time_system = round(psutil.cpu_times().system,1) + cpu_time_idle = round(psutil.cpu_times().idle,1) + network_sent = round(psutil.net_io_counters().bytes_sent / 1024**3, 6) + network_recv = round(psutil.net_io_counters().bytes_recv / 1024**3, 6) + return {"disk_space": {"total": disk_total, "used": disk_used, "free" : disk_free, "used_percentage" : disk_used_percentage}, + "memory": {"total": memory_total, "used_percentage": memory_perc}, + "cpu_time" : {"user": cpu_time_user, "system": cpu_time_system, "idle": cpu_time_idle}, + "network": {"sent": network_sent, "received": network_recv}} # Thread function to insert data from the queue into the database def insert_queue2db(): diff --git a/v2realbot/static/index.html b/v2realbot/static/index.html index 53cb6b7..b9c936f 100644 --- a/v2realbot/static/index.html +++ b/v2realbot/static/index.html @@ -131,9 +131,27 @@ +
+
+ +
+
+
+ Disk Space: + Free: -- GB | + Total: -- GB | + Used: -- % +
+
+
+
+
+
-
+
@@ -230,6 +248,7 @@
+