feat: Implemented expanded monitoring

This commit is contained in:
2025-08-18 12:55:49 -05:00
parent 9ac382e23e
commit 9159520e8f
2 changed files with 68 additions and 2 deletions

View File

@@ -33,6 +33,12 @@ The project will be composed of the following files:
- The agent must be able to collect and parse network metrics. - The agent must be able to collect and parse network metrics.
- The parsing of this data should result in a structured format (JSON or Python dictionary). - The parsing of this data should result in a structured format (JSON or Python dictionary).
### 3.3. Monitored Metrics
- **CPU Temperature**: The agent will monitor the CPU temperature.
- **GPU Temperature**: The agent will monitor the GPU temperature.
- **System Login Attempts**: The agent will monitor system login attempts.
### 3.3. LLM Analysis ### 3.3. LLM Analysis
- The agent must use a local LLM (via Ollama) to analyze the collected data. - The agent must use a local LLM (via Ollama) to analyze the collected data.

View File

@@ -7,6 +7,7 @@ import ollama
from discord_webhook import DiscordWebhook from discord_webhook import DiscordWebhook
import requests import requests
import data_storage import data_storage
import jc
# Load configuration # Load configuration
import config import config
@@ -42,6 +43,53 @@ def get_network_metrics():
print(f"Error parsing network metrics: {e}") print(f"Error parsing network metrics: {e}")
return None return None
def get_cpu_temperature():
"""Gets the CPU temperature using the sensors command."""
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:
print(f"Error getting CPU temperature: {e}")
return None
def get_gpu_temperature():
"""Gets the GPU temperature using the sensors command."""
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) 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."""
try:
with open("/var/log/auth.log", "r") as f:
log_lines = f.readlines()
failed_logins = []
for line in log_lines:
if "Failed password" in line:
failed_logins.append(line.strip())
return {"failed_login_attempts": failed_logins}
except FileNotFoundError:
print("Error: /var/log/auth.log not found.")
return {"failed_login_attempts": []}
except Exception as e:
print(f"Error reading login attempts: {e}")
return {"failed_login_attempts": []}
# --- LLM Interaction Function --- # --- LLM Interaction Function ---
def analyze_data_with_llm(data, baselines): def analyze_data_with_llm(data, baselines):
@@ -116,11 +164,17 @@ if __name__ == "__main__":
print("Running in test mode...") print("Running in test mode...")
system_logs = get_system_logs() system_logs = get_system_logs()
network_metrics = get_network_metrics() network_metrics = get_network_metrics()
cpu_temp = get_cpu_temperature()
gpu_temp = get_gpu_temperature()
login_attempts = get_login_attempts()
if system_logs and network_metrics: if system_logs and network_metrics:
combined_data = { combined_data = {
"system_logs": system_logs, "system_logs": system_logs,
"network_metrics": network_metrics "network_metrics": network_metrics,
"cpu_temperature": cpu_temp,
"gpu_temperature": gpu_temp,
"login_attempts": login_attempts
} }
data_storage.store_data(combined_data) data_storage.store_data(combined_data)
@@ -138,11 +192,17 @@ if __name__ == "__main__":
print("Running monitoring cycle...") print("Running monitoring cycle...")
system_logs = get_system_logs() system_logs = get_system_logs()
network_metrics = get_network_metrics() network_metrics = get_network_metrics()
cpu_temp = get_cpu_temperature()
gpu_temp = get_gpu_temperature()
login_attempts = get_login_attempts()
if system_logs and network_metrics: if system_logs and network_metrics:
combined_data = { combined_data = {
"system_logs": system_logs, "system_logs": system_logs,
"network_metrics": network_metrics "network_metrics": network_metrics,
"cpu_temperature": cpu_temp,
"gpu_temperature": gpu_temp,
"login_attempts": login_attempts
} }
data_storage.store_data(combined_data) data_storage.store_data(combined_data)