mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Add total RAM, CPUs and disk size to servers summary as well as disk usage in percent. Fixes https://github.com/GNS3/gns3-server/issues/1532
This commit is contained in:
1 parent
00a6765405
commit
3dc4ea46d6
11 files changed
+69
-9
No files matched your search
@@ -16,11 +16,13 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import sys
|
||||
import psutil
|
||||
|
||||
from gns3server.web.route import Route
|
||||
from gns3server.schemas.capabilities import CAPABILITIES_SCHEMA
|
||||
from gns3server.version import __version__
|
||||
from gns3server.compute import MODULES
|
||||
from gns3server.utils.path import get_default_project_directory
|
||||
|
||||
|
||||
class CapabilitiesHandler:
|
||||
@@ -38,5 +40,8 @@ class CapabilitiesHandler:
|
||||
response.json({
|
||||
"version": __version__,
|
||||
"platform": sys.platform,
|
||||
"cpus": psutil.cpu_count(logical=True),
|
||||
"memory": psutil.virtual_memory().total,
|
||||
"disk_size": psutil.disk_usage(get_default_project_directory()).total,
|
||||
"node_types": node_types
|
||||
})
|
||||
@@ -20,12 +20,12 @@ import asyncio
|
||||
import json
|
||||
import os
|
||||
import psutil
|
||||
import tempfile
|
||||
|
||||
from gns3server.web.route import Route
|
||||
from gns3server.compute.project_manager import ProjectManager
|
||||
from gns3server.compute import MODULES
|
||||
from gns3server.utils.cpu_percent import CpuPercent
|
||||
from gns3server.utils.path import get_default_project_directory
|
||||
|
||||
from gns3server.schemas.project import (
|
||||
PROJECT_OBJECT_SCHEMA,
|
||||
@@ -211,6 +211,7 @@ class ProjectHandler:
|
||||
# Non blocking call in order to get cpu usage. First call will return 0
|
||||
stats["cpu_usage_percent"] = CpuPercent.get(interval=None)
|
||||
stats["memory_usage_percent"] = psutil.virtual_memory().percent
|
||||
stats["disk_usage_percent"] = psutil.disk_usage(get_default_project_directory()).percent
|
||||
return {"action": "ping", "event": stats}
|
||||
|
||||
@Route.get(
|
||||
|
||||
@@ -25,6 +25,7 @@ from gns3server.schemas.server_statistics import SERVER_STATISTICS_SCHEMA
|
||||
from gns3server.compute.port_manager import PortManager
|
||||
from gns3server.utils.cpu_percent import CpuPercent
|
||||
from gns3server.version import __version__
|
||||
from gns3server.utils.path import get_default_project_directory
|
||||
from aiohttp.web import HTTPConflict
|
||||
|
||||
|
||||
@@ -61,7 +62,7 @@ class ServerHandler:
|
||||
load_average_percent = [int(x / psutil.cpu_count() * 100) for x in psutil.getloadavg()]
|
||||
memory_percent = int(psutil.virtual_memory().percent)
|
||||
swap_percent = int(psutil.swap_memory().percent)
|
||||
disk_usage_percent = int(psutil.disk_usage('/').percent)
|
||||
disk_usage_percent = int(psutil.disk_usage(get_default_project_directory()).percent)
|
||||
except psutil.Error as e:
|
||||
raise HTTPConflict(text="Psutil error detected: {}".format(e))
|
||||
response.json({"memory_total": memory_total,
|
||||
|
||||
Reference in new issue
Block a user