fix: Handle missing sensors command gracefully
This commit is contained in:
@@ -45,18 +45,28 @@ def get_network_metrics():
|
||||
|
||||
def get_cpu_temperature():
|
||||
"""Gets the CPU temperature using the sensors command."""
|
||||
try:
|
||||
subprocess.check_output(["sensors"], text=True)
|
||||
except (subprocess.CalledProcessError, FileNotFoundError):
|
||||
print("Error: 'sensors' command not found. Please install lm-sensors.")
|
||||
return {"cpu_temperature": "N/A"}
|
||||
try:
|
||||
sensors_output = subprocess.check_output(["sensors"], text=True)
|
||||
parsed_sensors = jc.parse('sensors', sensors_output)
|
||||
# This is a simplified example, you may need to adjust the parsing logic based on your specific hardware
|
||||
cpu_temp = parsed_sensors[0]['values'][0]['input']
|
||||
return {"cpu_temperature": cpu_temp}
|
||||
except (subprocess.CalledProcessError, FileNotFoundError, KeyError, IndexError) as e:
|
||||
except (subprocess.CalledProcessError, FileNotFoundError, KeyError, IndexError, jc.exceptions.ParseError) as e:
|
||||
print(f"Error getting CPU temperature: {e}")
|
||||
return None
|
||||
return {"cpu_temperature": "N/A"}
|
||||
|
||||
def get_gpu_temperature():
|
||||
"""Gets the GPU temperature using the sensors command."""
|
||||
try:
|
||||
subprocess.check_output(["sensors"], text=True)
|
||||
except (subprocess.CalledProcessError, FileNotFoundError):
|
||||
print("Error: 'sensors' command not found. Please install lm-sensors.")
|
||||
return {"gpu_temperature": "N/A"}
|
||||
try:
|
||||
sensors_output = subprocess.check_output(["sensors"], text=True)
|
||||
parsed_sensors = jc.parse('sensors', sensors_output)
|
||||
@@ -67,7 +77,7 @@ def get_gpu_temperature():
|
||||
gpu_temp = adapter['values'][0]['input']
|
||||
return {"gpu_temperature": gpu_temp}
|
||||
return {"gpu_temperature": "N/A"}
|
||||
except (subprocess.CalledProcessError, FileNotFoundError, KeyError, IndexError) as e:
|
||||
except (subprocess.CalledProcessError, FileNotFoundError, KeyError, IndexError, jc.exceptions.ParseError) as e:
|
||||
print(f"Error getting GPU temperature: {e}")
|
||||
return {"gpu_temperature": "N/A"}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user