Step 08 — Observability con Actuator¶
Obiettivo: health check, metriche, integrazione Prometheus.
Endpoint esposti¶
application.yml
management:
endpoints:
web:
exposure:
include: health,info,metrics,prometheus
endpoint:
health:
show-details: when_authorized
probes:
enabled: true # liveness + readiness
| Endpoint | Scopo |
|---|---|
/actuator/health | Health complessivo (UP/DOWN) |
/actuator/health/liveness | "L'app è viva?" → restart se DOWN |
/actuator/health/readiness | "L'app può ricevere traffico?" → load balancer drain |
/actuator/info | Metadati app + git info |
/actuator/metrics | Metriche Micrometer (JVM, HTTP, JDBC, …) |
/actuator/prometheus | Metriche in formato Prometheus |
Scraping Prometheus¶
ops/prometheus.yml
scrape_configs:
- job_name: sbfs-app
metrics_path: /actuator/prometheus
static_configs:
- targets: ["app:8080"]
Avvia tutto con docker compose up e visita http://localhost:9090 per esplorare le metriche.
Differenze tra profili¶
In prod la health è ridotta:
application-prod.yml
management:
endpoints:
web:
exposure:
include: health,info,prometheus
endpoint:
health:
show-details: never
→ Niente leak di info interne (versioni librerie, hostname DB, …).
Esercizi¶
- Aggiungi un
HealthIndicatorcustom che verifica la disponibilità di un servizio esterno. - Aggiungi un counter Micrometer per le transizioni di stato dei task.
- Spiega differenza tra liveness e readiness in Kubernetes.