Initial commit — Serveur Lucas SmartEye
API réception alertes chute (SmartEye/YOLO), analyse IA (Gemini 2.5 Flash), gestion alertes avec escalade (watchdog), notifications Firebase, dashboard web, documentation MkDocs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
125
check_gemini_health.py
Executable file
125
check_gemini_health.py
Executable file
@@ -0,0 +1,125 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Script de monitoring pour surveiller la santé de l'API Gemini
|
||||
Affiche les statistiques d'erreurs et les dernières erreurs
|
||||
"""
|
||||
import os
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
print("="*70)
|
||||
print("MONITORING SANTÉ API GEMINI")
|
||||
print("="*70)
|
||||
|
||||
# Fichiers de log
|
||||
error_log = "/tmp/smarteye_gemini_errors.log"
|
||||
error_counter = "/tmp/smarteye_gemini_error_count"
|
||||
error_lock = "/tmp/smarteye_gemini_error_last"
|
||||
|
||||
# 1. Statistiques d'erreurs
|
||||
print("\n📊 STATISTIQUES D'ERREURS")
|
||||
print("-"*70)
|
||||
|
||||
if os.path.exists(error_counter):
|
||||
try:
|
||||
with open(error_counter, 'r') as f:
|
||||
data = json.loads(f.read())
|
||||
error_count = data.get("count", 0)
|
||||
first_error = data.get("first_error")
|
||||
last_error = data.get("last_error")
|
||||
|
||||
print(f"Nombre d'erreurs (dernière heure): {error_count}")
|
||||
|
||||
if first_error:
|
||||
first_dt = datetime.fromtimestamp(first_error)
|
||||
print(f"Première erreur: {first_dt.strftime('%Y-%m-%d %H:%M:%S')}")
|
||||
|
||||
if last_error:
|
||||
last_dt = datetime.fromtimestamp(last_error)
|
||||
print(f"Dernière erreur: {last_dt.strftime('%Y-%m-%d %H:%M:%S')}")
|
||||
|
||||
# Évaluation de la santé
|
||||
if error_count == 0:
|
||||
print("✓ Statut: EXCELLENT - Aucune erreur")
|
||||
elif error_count < 3:
|
||||
print("⚠ Statut: BON - Quelques erreurs mineures")
|
||||
elif error_count < 5:
|
||||
print("⚠ Statut: ATTENTION - Erreurs modérées")
|
||||
else:
|
||||
print("✗ Statut: CRITIQUE - Problème récurrent détecté")
|
||||
except Exception as e:
|
||||
print(f"Erreur lecture compteur: {e}")
|
||||
else:
|
||||
print("✓ Aucune erreur enregistrée")
|
||||
|
||||
# 2. Cooldown actif
|
||||
print("\n⏱️ COOLDOWN ANTI-SPAM")
|
||||
print("-"*70)
|
||||
|
||||
if os.path.exists(error_lock):
|
||||
try:
|
||||
with open(error_lock, 'r') as f:
|
||||
last_alert = float(f.read().strip())
|
||||
last_alert_dt = datetime.fromtimestamp(last_alert)
|
||||
now = datetime.now().timestamp()
|
||||
remaining = max(0, 300 - (now - last_alert))
|
||||
|
||||
print(f"Dernière alerte envoyée: {last_alert_dt.strftime('%Y-%m-%d %H:%M:%S')}")
|
||||
|
||||
if remaining > 0:
|
||||
print(f"⏳ Cooldown actif: {int(remaining)} secondes restantes")
|
||||
else:
|
||||
print("✓ Cooldown terminé - Alertes autorisées")
|
||||
except Exception as e:
|
||||
print(f"Erreur lecture cooldown: {e}")
|
||||
else:
|
||||
print("✓ Pas de cooldown actif")
|
||||
|
||||
# 3. Dernières erreurs du log
|
||||
print("\n📋 DERNIÈRES ERREURS (10 dernières lignes)")
|
||||
print("-"*70)
|
||||
|
||||
if os.path.exists(error_log):
|
||||
try:
|
||||
with open(error_log, 'r') as f:
|
||||
lines = f.readlines()
|
||||
last_lines = lines[-30:] if len(lines) > 30 else lines
|
||||
|
||||
if last_lines:
|
||||
print(''.join(last_lines))
|
||||
else:
|
||||
print("✓ Aucune erreur dans le log")
|
||||
except Exception as e:
|
||||
print(f"Erreur lecture log: {e}")
|
||||
else:
|
||||
print("✓ Fichier de log non trouvé (aucune erreur)")
|
||||
|
||||
# 4. Recommandations
|
||||
print("\n💡 RECOMMANDATIONS")
|
||||
print("-"*70)
|
||||
|
||||
if os.path.exists(error_counter):
|
||||
try:
|
||||
with open(error_counter, 'r') as f:
|
||||
data = json.loads(f.read())
|
||||
error_count = data.get("count", 0)
|
||||
|
||||
if error_count >= 5:
|
||||
print("⚠ ACTIONS RECOMMANDÉES:")
|
||||
print(" 1. Vérifier la validité de la clé API Gemini")
|
||||
print(" 2. Vérifier la connectivité réseau")
|
||||
print(" 3. Consulter le log détaillé: /tmp/smarteye_gemini_errors.log")
|
||||
print(" 4. Vérifier les quotas API Google")
|
||||
print(" 5. Tester manuellement l'API avec check_models.py")
|
||||
elif error_count >= 3:
|
||||
print("ℹ️ Surveillance recommandée - Quelques erreurs détectées")
|
||||
else:
|
||||
print("✓ Système fonctionnel - Aucune action requise")
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
print("✓ Système fonctionnel - Aucune action requise")
|
||||
|
||||
print("\n" + "="*70)
|
||||
print("Fin du rapport")
|
||||
print("="*70)
|
||||
Reference in New Issue
Block a user