====== Runbook: Health Check ======
**Durata:** ~2 minuti \\
**Ruolo:** Operatore Gateway \\
**Frequenza:** Giornaliera / Automatizzata
Verifica della disponibilita e funzionalita del Gateway.
----
===== Workflow =====
flowchart TD
A[Avviare Health Check] --> B[/health Endpoint]
B --> C{Healthy?}
C -->|Si| D[Test API]
C -->|No| E[Controllare log]
D --> F{Dati restituiti?}
F -->|Si| G[OK - Finito]
F -->|No| H[Verificare DSN]
E --> I[Riavviare server]
H --> I
style G fill:#e8f5e9
style E fill:#ffebee
style H fill:#fff3e0
----
===== 1. Health Check Base =====
# Health Check semplice
curl -s -o /dev/null -w "%{http_code}" http://localhost:5000/health
# Risposta attesa: 200
# Con Response-Body
curl -s http://localhost:5000/health
# Risposta attesa: "Healthy"
----
===== 2. Health Check Esteso =====
# Swagger raggiungibile?
curl -s -o /dev/null -w "%{http_code}" http://localhost:5000/swagger
# Verificare versione API
curl -s http://localhost:5000/api/v1/info | jq
----
===== 3. Connettivita DSN =====
# Testare tutti i DSN
for dsn in demo produzione reporting; do
echo "Testing $dsn..."
curl -s -o /dev/null -w "$dsn: %{http_code}\n" \
"http://localhost:5000/api/v1/dsn/$dsn/tables"
done
**Versione PowerShell:**
$dsns = @("demo", "produzione", "reporting")
foreach ($dsn in $dsns) {
$result = Invoke-WebRequest -Uri "http://localhost:5000/api/v1/dsn/$dsn/tables" -UseBasicParsing
Write-Host "$dsn : $($result.StatusCode)"
}
----
===== 4. Misurare tempo di risposta =====
# Singola query
curl -s -o /dev/null -w "Tempo: %{time_total}s\n" \
"http://localhost:5000/api/v1/dsn/demo/tables/Products?\$top=10"
# Piu esecuzioni
for i in {1..5}; do
curl -s -o /dev/null -w "%{time_total}\n" \
"http://localhost:5000/api/v1/dsn/demo/tables/Products?\$top=10"
done | awk '{sum+=$1} END {print "Media: " sum/NR "s"}'
----
===== 5. Checklist =====
| # | Punto di verifica | Atteso | v |
|---|-----------|-----------|---|
| 1 | /health | 200 + "Healthy" | ☐ |
| 2 | /swagger | 200 | ☐ |
| 3 | DSN "demo" raggiungibile | 200 | ☐ |
| 4 | Tempo di risposta | < 1s | ☐ |
| 5 | Nessun errore nei log | Nessun ERROR | ☐ |
----
===== Health Check Automatizzato =====
**Cron (Linux):**
# /etc/cron.d/gateway-health
*/5 * * * * root curl -sf http://localhost:5000/health || systemctl restart data-gateway
**Scheduled Task (Windows):**
# health-check.ps1
$response = Invoke-WebRequest -Uri "http://localhost:5000/health" -UseBasicParsing -TimeoutSec 5
if ($response.StatusCode -ne 200) {
Restart-Service -Name "DataGateway" -Force
Send-MailMessage -To "admin@example.com" -Subject "Gateway Restart" -Body "Il Gateway e stato riavviato automaticamente"
}
----
===== Troubleshooting =====
| Problema | Causa | Soluzione |
|---------|---------|--------|
| ''Connection refused'' | Gateway non avviato | Avviare server |
| ''503 Service Unavailable'' | Avvio non completato | Attendere 30s, riprovare |
| ''500 Internal Server Error'' | Errore configurazione | Controllare log |
| Timeout | Gateway sovraccarico | Ridurre carico, aumentare risorse |
----
===== Soglie =====
| Metrica | Verde | Giallo | Rosso |
|--------|------|------|-----|
| Tempo di risposta | < 500ms | 500ms-2s | > 2s |
| Error-Rate | < 1% | 1-5% | > 5% |
| CPU | < 50% | 50-80% | > 80% |
| Memoria | < 70% | 70-90% | > 90% |
----
===== Runbook Correlati =====
* [[.:server-starten|Avviare server]] - In caso di guasto
* [[.:logs-pruefen|Controllare log]] - Analisi errori
* [[..:monitoring:prometheus|Prometheus]] - Monitoraggio automatico
----
<< [[.:dsn-verwalten|<- Gestire DSN]] | [[.:logs-pruefen|-> Controllare log]] >>
----
//Wolfgang van der Stille @ EMSR DATA d.o.o. - Data Gateway Professional//
{{tag>operator runbook health check monitoring}}