Changes in source code to collect application metrics
Spring Boot 2 introduced support for producing performance metrics in a Prometheus format using the Micrometer library (https://micrometer.io). There’s only one change we need to make to the source code of the microservices: we need to add a dependency on the Micrometer library, micrometer-registry-prometheus
, in the Gradle build files, build.gradle
. The dependency looks like this:
implementation 'io.micrometer:micrometer-registry-prometheus'
This will make the microservices produce Prometheus metrics on port 4004
using the /actuator/prometheus
path.
In Chapter 18, we separated the management port, used by the actuator, from the port serving requests to APIs exposed by a microservice. See the Observing the service mesh section for a recap, if required.
To let Prometheus know about these endpoints, each microservice’s Pod is annotated with the following code:
annotations:...