File size: 5,090 Bytes
4485fc2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | #!/bin/bash
# Script de inicialização em modo console (sem GUI)
echo "🚀 Iniciando Sistema de Monitoramento GPU (Modo Console)"
echo "========================================================"
cd /home/crhon/gpu_monitoring_system
# Testar detecção de GPU
echo "📡 Testando detecção de GPU..."
python3 -c "
from gpu_monitoring import GPUManager
import logging
logging.basicConfig(level=logging.INFO)
try:
manager = GPUManager()
if manager.initialize():
gpus = manager.get_gpu_list()
print(f'✓ GPUs detectadas: {gpus}')
# Testar coleta de status
status = manager.get_status()
for gpu_name, gpu_status in status.items():
if gpu_status:
print(f' {gpu_name}: {gpu_status.temperature}°C, {gpu_status.load}%, {gpu_status.power_draw}W')
else:
print('✗ Nenhuma GPU detectada')
except Exception as e:
print(f'✗ Erro na detecção: {e}')
"
echo ""
echo "💨 Iniciando controle de fan (modo console)..."
python3 -c "
from gpu_fan_controller import FanController
import logging
import time
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
try:
controller = FanController()
if controller.initialize():
print('✓ Fan controller inicializado')
print(f' GPU: {controller.gpu_name}')
print(f' Perfil padrão: {controller.current_profile.name if controller.current_profile else \"Nenhum\"}')
# Testar controle manual
controller.set_manual_pwm(100)
time.sleep(2)
status = controller.get_status()
if status:
print(f' PWM atual: {status.current_pwm}')
print(f' Modo: {status.mode.value}')
print('✓ Controle de fan testado com sucesso')
else:
print('✗ Falha ao inicializar controle de fan')
except Exception as e:
print(f'✗ Erro no controle de fan: {e}')
" &
FAN_PID=$!
echo "✓ Controle de fan iniciado (PID: $FAN_PID)"
echo ""
echo "🌐 Iniciando interface web..."
python3 web_interface.py &
WEB_PID=$!
echo "✓ Interface web iniciada (PID: $WEB_PID)"
echo " Acesse: http://localhost:5000"
echo ""
echo "🚨 Iniciando sistema de alertas..."
python3 -c "
from alert_system import AlertManager
import logging
import time
logging.basicConfig(level=logging.INFO)
try:
alert_manager = AlertManager()
alert_manager.start()
print('✓ Sistema de alertas iniciado')
# Testar threshold
thresholds = alert_manager.thresholds
print(f' Thresholds configurados: {len(thresholds)}')
for threshold in thresholds[:3]: # Mostrar os 3 primeiros
print(f' {threshold.metric} >= {threshold.threshold}°C ({threshold.duration}s)')
except Exception as e:
print(f'✗ Erro no sistema de alertas: {e}')
" &
ALERT_PID=$!
echo "✓ Sistema de alertas iniciado (PID: $ALERT_PID)"
echo ""
echo "📊 Iniciando monitoramento de performance..."
python3 -c "
from performance_optimizer import SystemOptimizer
import logging
logging.basicConfig(level=logging.INFO)
try:
optimizer = SystemOptimizer()
optimizer.start_monitoring()
print('✓ Monitoramento de performance iniciado')
# Testar perfis
profiles = optimizer.profiles
print(f' Perfis disponíveis: {len(profiles)}')
for name, profile in profiles.items():
print(f' {name}: {profile.description}')
except Exception as e:
print(f'✗ Erro no monitoramento de performance: {e}')
" &
PERF_PID=$!
echo "✓ Monitoramento de performance iniciado (PID: $PERF_PID)"
echo ""
echo "✅ Sistema iniciado com sucesso!"
echo "==============================="
echo ""
echo "📍 Componentes ativos:"
echo " • Controle de Fan: PID $FAN_PID"
echo " • Interface Web: PID $WEB_PID (http://localhost:5000)"
echo " • Sistema de Alertas: PID $ALERT_PID"
echo " • Monitoramento Performance: PID $PERF_PID"
echo ""
echo "💡 Dicas:"
echo " • Acesse a interface web para controle avançado"
echo " • Use Ctrl+C para parar o sistema"
echo " • Logs estão sendo salvos nos arquivos de log"
echo ""
echo "🎯 Sistema pronto para monitoramento!"
# Função para parar o sistema
stop_system() {
echo ""
echo "🛑 Parando sistema..."
kill $FAN_PID $WEB_PID $ALERT_PID $PERF_PID 2>/dev/null
echo "✓ Sistema parado"
exit 0
}
# Configurar trap para parada controlada
trap stop_system INT TERM
# Loop de monitoramento
echo ""
echo "🔄 Sistema em execução. Pressione Ctrl+C para parar."
while true; do
sleep 30
# Verificar se os processos ainda estão ativos
if ! kill -0 $FAN_PID $WEB_PID $ALERT_PID $PERF_PID 2>/dev/null; then
echo "⚠ Atenção: Um ou mais processos foram encerrados inesperadamente"
echo " Verifique os logs para detalhes"
fi
# Testar status do web server
if curl -s http://localhost:5000/api/status > /dev/null 2>&1; then
echo "✓ Web interface respondendo"
else
echo "⚠ Web interface não respondendo"
fi
done |