Watch over Temps

This commit is contained in:
2025-08-18 14:32:39 -05:00
parent 4d8b4d6114
commit 524120c9f2
8 changed files with 69 additions and 36 deletions

View File

@@ -7,7 +7,6 @@ import ollama
from discord_webhook import DiscordWebhook
import requests
import data_storage
import jc
# Load configuration
import config
@@ -43,43 +42,40 @@ def get_network_metrics():
print(f"Error parsing network metrics: {e}")
return None
import re
def get_cpu_temperature():
"""Gets the CPU temperature using the sensors command."""
try:
subprocess.check_output(["sensors"], text=True)
sensors_output = subprocess.check_output(["sensors"], text=True)
# Use regex to find the CPU temperature
match = re.search(r"Package id 0:\s+\+([\d\.]+)", sensors_output)
if match:
return {"cpu_temperature": float(match.group(1))}
else:
return {"cpu_temperature": "N/A"}
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, jc.exceptions.ParseError) as e:
print(f"Error getting CPU temperature: {e}")
return {"cpu_temperature": "N/A"}
def get_gpu_temperature():
"""Gets the GPU temperature using the sensors command."""
try:
subprocess.check_output(["sensors"], text=True)
sensors_output = subprocess.check_output(["sensors"], text=True)
# Use regex to find the GPU temperature for amdgpu
match = re.search(r"edge:\s+\+([\d\.]+)", sensors_output)
if match:
return {"gpu_temperature": float(match.group(1))}
else:
# if amdgpu not found, try radeon
match = re.search(r"temp1:\s+\+([\d\.]+)", sensors_output)
if match:
return {"gpu_temperature": float(match.group(1))}
else:
return {"gpu_temperature": "N/A"}
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)
# This is a simplified example, you may need to adjust the parsing logic based on your specific hardware
# Look for the adapter that contains "amdgpu" or "radeon"
for adapter in parsed_sensors:
if 'amdgpu' in adapter.get('adapter', '').lower() or 'radeon' in adapter.get('adapter', '').lower():
gpu_temp = adapter['values'][0]['input']
return {"gpu_temperature": gpu_temp}
return {"gpu_temperature": "N/A"}
except (subprocess.CalledProcessError, FileNotFoundError, KeyError, IndexError, jc.exceptions.ParseError) as e:
print(f"Error getting GPU temperature: {e}")
return {"gpu_temperature": "N/A"}
def get_login_attempts():
"""Gets system login attempts from /var/log/auth.log."""
@@ -98,7 +94,7 @@ def get_login_attempts():
return {"failed_login_attempts": []}
except Exception as e:
print(f"Error reading login attempts: {e}")
return {"failed_login_attempts": []}
return {"failed_logins": []}
# --- LLM Interaction Function ---