-
add maven dependency
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
-
restart your app to check the following endpoints
-
http://localhost:8080/metrics - app metrics
-
http://localhost:8080/mappings - list all url mappings
-
-
write your own metrics and health indicator
@RestController class FlipFlopController implements HealthIndicator { private final AtomicLong requestCount = new AtomicLong(); private final CounterService counterService; FlipFlopController(CounterService counterService) { this.counterService = counterService; } @Override public Health health() { long count = requestCount.get(); return count % 2 == 1 ? Health.up().build() : Health.down().withDetail("count", count).build(); } @RequestMapping("/metered") String metered() { counterService.increment("metered.request.count"); return "ok" + requestCount.incrementAndGet(); } }
-
now restart your app, and go to http://localhost:8080/health (depends on the login, admin can view more details than user). Read the reference when you have time (optional)
admin view
{ "status": "DOWN", "flipFlopController": { "status": "DOWN", "count": 0 }, "diskSpace": { "status": "UP", "total": 499071844352, "free": 243076169728, "threshold": 10485760 }, "db": { "status": "UP", "database": "H2", "hello": 1 } }
-
hit the url http://localhost:8080/metered once and check the health endpoint again
-
hit the url http://localhost:8080/metrics to search for the key
metered.request.count
-
(optional) Experiment with more endpoints