mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
feat: Enhance information displayed on the system status dashboard
This commit is contained in:
1 parent
f65d9b17c6
commit
a35df76384
4 files changed
+73
-2
No files matched your search
@@ -21,7 +21,9 @@ API routes for compute.
|
||||
|
||||
import os
|
||||
import psutil
|
||||
import cpuinfo
|
||||
|
||||
from functools import lru_cache
|
||||
from gns3server.config import Config
|
||||
from gns3server.utils.cpu_percent import CpuPercent
|
||||
from gns3server.version import __version__
|
||||
@@ -42,6 +44,11 @@ from typing import Optional, List
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def get_cpu_model() -> str:
|
||||
return cpuinfo.get_cpu_info().get("brand_raw", "")
|
||||
|
||||
|
||||
@router.post("/projects/{project_id}/ports/udp", status_code=status.HTTP_201_CREATED)
|
||||
def allocate_udp_port(project_id: UUID) -> dict:
|
||||
"""
|
||||
@@ -119,10 +126,15 @@ def compute_statistics() -> dict:
|
||||
swap_free = psutil.swap_memory().free
|
||||
swap_used = psutil.swap_memory().used
|
||||
cpu_percent = int(CpuPercent.get())
|
||||
load_average_percent = [int(x / psutil.cpu_count() * 100) for x in psutil.getloadavg()]
|
||||
cpu_count = psutil.cpu_count(logical=True) or 1
|
||||
cpu_count_physical = psutil.cpu_count(logical=False)
|
||||
raw_load_average = psutil.getloadavg()
|
||||
load_average = [round(x, 2) for x in raw_load_average]
|
||||
load_average_percent = [round(x / cpu_count * 100, 2) for x in raw_load_average]
|
||||
memory_percent = int(psutil.virtual_memory().percent)
|
||||
swap_percent = int(psutil.swap_memory().percent)
|
||||
disk_usage_percent = int(psutil.disk_usage(get_default_project_directory()).percent)
|
||||
disk_usage = psutil.disk_usage(get_default_project_directory())
|
||||
disk_usage_percent = int(disk_usage.percent)
|
||||
except psutil.Error as e:
|
||||
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||
# raise HTTPConflict(text="Psutil error detected: {}".format(e))
|
||||
@@ -135,9 +147,16 @@ def compute_statistics() -> dict:
|
||||
"swap_free": swap_free,
|
||||
"swap_used": swap_used,
|
||||
"cpu_usage_percent": cpu_percent,
|
||||
"cpu_count": cpu_count,
|
||||
"cpu_count_physical": cpu_count_physical,
|
||||
"cpu_model": get_cpu_model(),
|
||||
"memory_usage_percent": memory_percent,
|
||||
"swap_usage_percent": swap_percent,
|
||||
"disk_usage_percent": disk_usage_percent,
|
||||
"disk_total": disk_usage.total,
|
||||
"disk_used": disk_usage.used,
|
||||
"disk_free": disk_usage.free,
|
||||
"load_average": load_average,
|
||||
"load_average_percent": load_average_percent,
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user