mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 03:08:14 +00:00
Catch exception when psutil returns OSError
This commit is contained in:
parent
855a95de49
commit
6761ae3445
@ -21,6 +21,9 @@ import psutil
|
||||
|
||||
from gns3server.utils.cpu_percent import CpuPercent
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class NotificationQueue(asyncio.Queue):
|
||||
"""
|
||||
@ -51,10 +54,14 @@ class NotificationQueue(asyncio.Queue):
|
||||
"""
|
||||
Return the content of the ping notification
|
||||
"""
|
||||
msg = {}
|
||||
msg = {"cpu_usage_percent": 0,
|
||||
"memory_usage_percent": 0}
|
||||
# Non blocking call in order to get cpu usage. First call will return 0
|
||||
try:
|
||||
msg["cpu_usage_percent"] = CpuPercent.get(interval=None)
|
||||
msg["memory_usage_percent"] = psutil.virtual_memory().percent
|
||||
except OSError as e:
|
||||
log.warning("Could not get CPU and memory usage from psutil: {}".format(e))
|
||||
return msg
|
||||
|
||||
async def get_json(self, timeout):
|
||||
|
Loading…
Reference in New Issue
Block a user