🖨️ Version PDF
Imaginez : votre API tourne chez un client. Il vous dit :
“Ça marche pas.”
Question : Qu’est-ce qui ne marche pas ?
Actuator ajoute des endpoints techniques. Ce ne sont pas des features métier (pas des “chien”, pas des “race”).
Ce sont des capteurs :
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
Redémarrer l’application Spring Boot…
curl http://localhost:8080/actuator/health
UP
DOWN
OUT_OF_SERVICE
Pourquoi c’est crucial ?
Par défaut, Actuator n’expose pas tout (bonne chose). On choisit.
management: endpoints: web: exposure: include: health,info,metrics,prometheus endpoint: health: show-details: when_authorized
info
On veut parfois savoir :
Exemple (application.yml) :
management: info: env: enabled: true info: app: name: wouaf-wouaf version: 1.0.0
Puis :
curl http://localhost:8080/actuator/info
metrics
Exemple :
curl "http://localhost:8080/actuator/metrics/http.server.requests"
Vous verrez :
Vous voulez savoir si “le module concours” répond ?
@Component public class ConcoursHealthIndicator implements HealthIndicator { private final ConcoursRepository repo; public ConcoursHealthIndicator(ConcoursRepository repo) { this.repo = repo; } @Override public Health health() { try { repo.count(); // appel simple pour vérifier DB + table return Health.up().withDetail("concours", "OK").build(); } catch (Exception e) { return Health.down().withDetail("concours", "KO").build(); } } }
Règle pédagogique :
Sinon vous exposez des infos sensibles.
Outil de monitoring → /actuator/health → Spring Boot → DB
HealthIndicator
/actuator/beans