This commit is contained in:
Marcos
2026-03-22 10:10:27 -03:00
parent f72677ef27
commit 6589c62b18
4 changed files with 327 additions and 153 deletions

View File

@@ -1,6 +1,7 @@
import subprocess
import os
import psutil
import time
def run_bash_command(command: str) -> str:
"""Executa um comando bash na VPS e retorna a saída."""
@@ -26,11 +27,19 @@ def run_bash_command(command: str) -> str:
return f"ERRO fatal ao rodar bash: {str(e)}"
def get_system_health() -> str:
"""Retorna um texto base rápido da saúde atual do servidor para a IA analisar."""
"""Retorna um texto detalhado da saúde do servidor para a IA."""
cpu = psutil.cpu_percent(interval=0.1)
ram = psutil.virtual_memory().percent
disk = psutil.disk_usage('/').percent
return f"CPU: {cpu}% | RAM Usada: {ram}% | Disco Usado: {disk}%"
vm = psutil.virtual_memory()
disk = psutil.disk_usage('/')
# Uptime aproximado usando psutil
uptime_seconds = time.time() - psutil.boot_time()
uptime_hours = round(uptime_seconds / 3600, 1)
return (f"CPU: {cpu}% | "
f"RAM: {round(vm.used / (1024**3), 2)}GB usada / {round(vm.total / (1024**3), 2)}GB total ({vm.percent}%) | "
f"Disco: {disk.percent}% usado | "
f"Uptime: {uptime_hours}h")
def read_vps_file(filepath: str) -> str:
"""Lê um arquivo do sistema de arquivos da VPS através do mapeamento /host_root."""