You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+17Lines changed: 17 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,8 @@ This demo app shows how a Spring Boot application can expose a Prometheus metric
4
4
5
5
🚼 The app was initially created with [Spring Initializr][init] and then by following the [RESTful service tutorial on spring.io][rest-tutorial].
6
6
7
+
## To run
8
+
7
9
To run the app:
8
10
9
11
mvn clean spring-boot:run
@@ -24,6 +26,19 @@ This will expose Prometheus metrics at `/actuator/prometheus`. This is a simple
24
26
tomcat_sessions_alive_max_seconds 0.0
25
27
...
26
28
29
+
## Timing a custom method
30
+
31
+
The method in the application which responds to the REST request has been annotated with `@Timed`, so Micrometer will capture the execution time of this method:
32
+
33
+
```java
34
+
@GetMapping("/greeting")
35
+
@Timed(value="greeting.time", description="Time taken to return greeting",
Once you make a request to the service at <http://localhost:8080/greeting>, you will also see a new metric exposed, `greeting_time_seconds` exposed, which shows the execution time of the `greeting` method:
28
43
29
44
# HELP greeting_time_seconds Time taken to return greeting
@@ -43,6 +58,8 @@ From the [Micrometer docs][timerdocs]:
43
58
44
59
> All implementations of _Timer_ report at least the total time and count of events as separate time series.
45
60
61
+
## Getting metrics into Prometheus
62
+
46
63
Now we need to get these metrics into Prometheus.
47
64
48
65
In another terminal, use Podman to start an ephemeral Prometheus in a container, and use the `host` networking option, which will allow the container to access the Spring Boot app on `localhost`:
0 commit comments