diff --git a/main.py b/main.py index c8df3bd..47e6549 100644 --- a/main.py +++ b/main.py @@ -22,10 +22,6 @@ else: app = FastAPI() -cpu_normal = True -ram_normal = True -disk_normal = True - SessionLocal = sessionmaker(bind=engine) Base = declarative_base() @@ -143,17 +139,22 @@ def get_info(): db.close() raise HTTPException(status_code=404, detail="Limits not found") delta_seconds = int(time.time() - start_time) + cpu_percent = psutil.cpu_percent(interval=0.5) + ram_percent = psutil.virtual_memory().percent + disk_percent = psutil.disk_usage('/').percent + + system_information = Info( uptime=datetime.datetime.now() - datetime.timedelta(seconds=delta_seconds), - cpu=psutil.cpu_percent(interval=0.5), - ram=psutil.virtual_memory().percent, - disk=psutil.disk_usage('/').percent, + cpu=cpu_percent, + ram=ram_percent, + disk=disk_percent, cpu_threshold=limits.cpu_threshold, ram_threshold=limits.ram_threshold, disk_threshold=limits.disk_threshold, - cpu_normal=cpu_normal, - ram_normal=ram_normal, - disk_normal=disk_normal + cpu_normal= cpu_percent <= limits.cpu_threshold, + ram_normal=ram_percent <= limits.cpu_threshold, + disk_normal=disk_percent <= limits.cpu_threshold, ) print(system_information) return system_information diff --git a/webroot/index.html b/webroot/index.html index 5eda061..cd0f6b5 100644 --- a/webroot/index.html +++ b/webroot/index.html @@ -96,22 +96,22 @@ const cpuTd = document.createElement('td'); cpuTd.style.textAlign = 'center'; cpuTd.style.padding = '8px 4px'; - cpuTd.textContent = item.cpu === 1 ? '↑' : '↓'; - cpuTd.style.color = item.cpu === 1 ? 'red' : 'green'; + cpuTd.textContent = item.cpu_overage === 1 ? '↑' : '↓'; + cpuTd.style.color = item.cpu_overage === 1 ? 'red' : 'green'; // RAM const ramTd = document.createElement('td'); ramTd.style.textAlign = 'center'; ramTd.style.padding = '8px 4px'; - ramTd.textContent = item.ram === 1 ? '↑' : '↓'; - ramTd.style.color = item.ram === 1 ? 'red' : 'green'; + ramTd.textContent = item.ram_overage === 1 ? '↑' : '↓'; + ramTd.style.color = item.ram_overage === 1 ? 'red' : 'green'; // DISK const diskTd = document.createElement('td'); diskTd.style.textAlign = 'center'; diskTd.style.padding = '8px 4px'; - diskTd.textContent = item.disk === 1 ? '↑' : '↓'; - diskTd.style.color = item.disk === 1 ? 'red' : 'green'; + diskTd.textContent = item.disk_overage === 1 ? '↑' : '↓'; + diskTd.style.color = item.disk_overage === 1 ? 'red' : 'green'; // Timestamp const tsTd = document.createElement('td');