From 86a9c20bb2dd7d707f3bcc438971e18047c93938 Mon Sep 17 00:00:00 2001 From: Braelyn Boynton Date: Thu, 2 May 2024 18:57:28 -0700 Subject: [PATCH] handle exception on grabbing host env --- agentops/host_env.py | 59 +++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/agentops/host_env.py b/agentops/host_env.py index 3b2890338..4eff0c89a 100644 --- a/agentops/host_env.py +++ b/agentops/host_env.py @@ -5,38 +5,51 @@ def get_sdk_details(): - return { - "AgentOps SDK Version": get_agentops_version(), - "Python Version": platform.python_version(), - } + try: + return { + "AgentOps SDK Version": get_agentops_version(), + "Python Version": platform.python_version(), + } + except: + return {} def get_os_details(): - return { - "Hostname": socket.gethostname(), - "OS": platform.system(), - "OS Version": platform.version(), - "OS Release": platform.release() - } + try: + return { + "Hostname": socket.gethostname(), + "OS": platform.system(), + "OS Version": platform.version(), + "OS Release": platform.release() + } + except: + return {} def get_cpu_details(): - return { - "Physical cores": psutil.cpu_count(logical=False), - "Total cores": psutil.cpu_count(logical=True), - # "Max Frequency": f"{psutil.cpu_freq().max:.2f}Mhz", # Fails right now - "CPU Usage": f"{psutil.cpu_percent()}%" - } + try: + return { + "Physical cores": psutil.cpu_count(logical=False), + "Total cores": psutil.cpu_count(logical=True), + # "Max Frequency": f"{psutil.cpu_freq().max:.2f}Mhz", # Fails right now + "CPU Usage": f"{psutil.cpu_percent()}%" + } + except: + return {} def get_ram_details(): - ram_info = psutil.virtual_memory() - return { - "Total": f"{ram_info.total / (1024**3):.2f} GB", - "Available": f"{ram_info.available / (1024**3):.2f} GB", - "Used": f"{ram_info.used / (1024**3):.2f} GB", - "Percentage": f"{ram_info.percent}%" - } + try: + ram_info = psutil.virtual_memory() + return { + "Total": f"{ram_info.total / (1024 ** 3):.2f} GB", + "Available": f"{ram_info.available / (1024 ** 3):.2f} GB", + "Used": f"{ram_info.used / (1024 ** 3):.2f} GB", + "Percentage": f"{ram_info.percent}%" + } + except: + return {} + def get_disk_details():