Skip to content

Commit f8fdc27

Browse files
committed
Update readme
1 parent e88a5d6 commit f8fdc27

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ This demo app shows how a Spring Boot application can expose a Prometheus metric
44

55
🚼 The app was initially created with [Spring Initializr][init] and then by following the [RESTful service tutorial on spring.io][rest-tutorial].
66

7+
## To run
8+
79
To run the app:
810

911
mvn clean spring-boot:run
@@ -24,6 +26,19 @@ This will expose Prometheus metrics at `/actuator/prometheus`. This is a simple
2426
tomcat_sessions_alive_max_seconds 0.0
2527
...
2628

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",
36+
percentiles = {0.5, 0.90})
37+
public Greeting greeting(@RequestParam(value = "name", defaultValue = "World") String name) {
38+
return new Greeting(counter.incrementAndGet(), String.format(template, name));
39+
}
40+
```
41+
2742
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:
2843

2944
# HELP greeting_time_seconds Time taken to return greeting
@@ -43,6 +58,8 @@ From the [Micrometer docs][timerdocs]:
4358

4459
> All implementations of _Timer_ report at least the total time and count of events as separate time series.
4560
61+
## Getting metrics into Prometheus
62+
4663
Now we need to get these metrics into Prometheus.
4764

4865
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

Comments
 (0)