fix attributes
This commit is contained in:
21
main.py
21
main.py
@@ -22,10 +22,6 @@ else:
|
|||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
cpu_normal = True
|
|
||||||
ram_normal = True
|
|
||||||
disk_normal = True
|
|
||||||
|
|
||||||
|
|
||||||
SessionLocal = sessionmaker(bind=engine)
|
SessionLocal = sessionmaker(bind=engine)
|
||||||
Base = declarative_base()
|
Base = declarative_base()
|
||||||
@@ -143,17 +139,22 @@ def get_info():
|
|||||||
db.close()
|
db.close()
|
||||||
raise HTTPException(status_code=404, detail="Limits not found")
|
raise HTTPException(status_code=404, detail="Limits not found")
|
||||||
delta_seconds = int(time.time() - start_time)
|
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(
|
system_information = Info(
|
||||||
uptime=datetime.datetime.now() - datetime.timedelta(seconds=delta_seconds),
|
uptime=datetime.datetime.now() - datetime.timedelta(seconds=delta_seconds),
|
||||||
cpu=psutil.cpu_percent(interval=0.5),
|
cpu=cpu_percent,
|
||||||
ram=psutil.virtual_memory().percent,
|
ram=ram_percent,
|
||||||
disk=psutil.disk_usage('/').percent,
|
disk=disk_percent,
|
||||||
cpu_threshold=limits.cpu_threshold,
|
cpu_threshold=limits.cpu_threshold,
|
||||||
ram_threshold=limits.ram_threshold,
|
ram_threshold=limits.ram_threshold,
|
||||||
disk_threshold=limits.disk_threshold,
|
disk_threshold=limits.disk_threshold,
|
||||||
cpu_normal=cpu_normal,
|
cpu_normal= cpu_percent <= limits.cpu_threshold,
|
||||||
ram_normal=ram_normal,
|
ram_normal=ram_percent <= limits.cpu_threshold,
|
||||||
disk_normal=disk_normal
|
disk_normal=disk_percent <= limits.cpu_threshold,
|
||||||
)
|
)
|
||||||
print(system_information)
|
print(system_information)
|
||||||
return system_information
|
return system_information
|
||||||
|
|||||||
@@ -96,22 +96,22 @@
|
|||||||
const cpuTd = document.createElement('td');
|
const cpuTd = document.createElement('td');
|
||||||
cpuTd.style.textAlign = 'center';
|
cpuTd.style.textAlign = 'center';
|
||||||
cpuTd.style.padding = '8px 4px';
|
cpuTd.style.padding = '8px 4px';
|
||||||
cpuTd.textContent = item.cpu === 1 ? '↑' : '↓';
|
cpuTd.textContent = item.cpu_overage === 1 ? '↑' : '↓';
|
||||||
cpuTd.style.color = item.cpu === 1 ? 'red' : 'green';
|
cpuTd.style.color = item.cpu_overage === 1 ? 'red' : 'green';
|
||||||
|
|
||||||
// RAM
|
// RAM
|
||||||
const ramTd = document.createElement('td');
|
const ramTd = document.createElement('td');
|
||||||
ramTd.style.textAlign = 'center';
|
ramTd.style.textAlign = 'center';
|
||||||
ramTd.style.padding = '8px 4px';
|
ramTd.style.padding = '8px 4px';
|
||||||
ramTd.textContent = item.ram === 1 ? '↑' : '↓';
|
ramTd.textContent = item.ram_overage === 1 ? '↑' : '↓';
|
||||||
ramTd.style.color = item.ram === 1 ? 'red' : 'green';
|
ramTd.style.color = item.ram_overage === 1 ? 'red' : 'green';
|
||||||
|
|
||||||
// DISK
|
// DISK
|
||||||
const diskTd = document.createElement('td');
|
const diskTd = document.createElement('td');
|
||||||
diskTd.style.textAlign = 'center';
|
diskTd.style.textAlign = 'center';
|
||||||
diskTd.style.padding = '8px 4px';
|
diskTd.style.padding = '8px 4px';
|
||||||
diskTd.textContent = item.disk === 1 ? '↑' : '↓';
|
diskTd.textContent = item.disk_overage === 1 ? '↑' : '↓';
|
||||||
diskTd.style.color = item.disk === 1 ? 'red' : 'green';
|
diskTd.style.color = item.disk_overage === 1 ? 'red' : 'green';
|
||||||
|
|
||||||
// Timestamp
|
// Timestamp
|
||||||
const tsTd = document.createElement('td');
|
const tsTd = document.createElement('td');
|
||||||
|
|||||||
Reference in New Issue
Block a user