From 1a3654e5b2531f448c04e937837e8d487c6bc32b Mon Sep 17 00:00:00 2001 From: Santiago Lo Coco Date: Tue, 12 Mar 2024 13:25:54 +0100 Subject: [PATCH] Add metrics endpoint --- .../src/main/java/com/example/demo/DataController.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spring-app/src/main/java/com/example/demo/DataController.java b/spring-app/src/main/java/com/example/demo/DataController.java index 74dbfd0..cbf538a 100644 --- a/spring-app/src/main/java/com/example/demo/DataController.java +++ b/spring-app/src/main/java/com/example/demo/DataController.java @@ -5,12 +5,20 @@ import org.springframework.web.bind.annotation.RestController; @RestController class DataController { + private static int callsCount = 0; + @GetMapping("/data") SomeData get() { + callsCount++; var ret = new SomeData(); ret.setName("ILV Microservice Architecture"); return ret; } + + @GetMapping("/metrics") + String metrics() { + return "# HELP calls_count Total number of calls\n# TYPE calls_count counter\ncalls_count " + callsCount; + } } class SomeData {