Monitoring your Spring Boot and Micronaut microservices
with Micrometer
JCON2020#
www.jcon.one
Ko Turk
Senior Java Developer
Our Partners 2020:
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
You’re part of a racing team
Sounds silly right?
But what if we don’t have this kind of information?
@KoTurk77@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
But why don’t we (developers) think about proper monitoring?
@KoTurk77@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
Title Text
https://formulaf1results.blogspot.com/2020/01/f1-crash-wallpaper.html
Application X Application Y
Backend
(still driving but slow)
@KoTurk77@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
If that’s happening…..
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
Of course you can log it but…..
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
A log is an event that happened
A metric is a measurement of the health of a system.
https://www.sumologic.com/blog/logs-metrics-overview/
@KoTurk77@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
That’s where
Micrometer comes in
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
Introduction
Working
for Blue4IT
@Rabobank
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
https://www.signifytechnology.com/blog/2019/09/whats-your-tech-stack
Java 14Spring Boot
Typescript
Angular
Cloud Foundry
Pipeline as code Micrometer
Speaking
about IDEs and Micrometer
Likes to drive
the trial bike
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
UtrechtJUG
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
Goals
Define the metrics
Create them in Micrometer
Save it to Prometheus
Visualize with Grafana
(Create the teams strategy)
(Preparing the car/race)
(The teams Pitwall)
https://www.redbull.com/nl-nl/red-bull-racing-zet-de-fabrieksdeuren-open
Create the teams strategy
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
What do we want to monitor?
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
How to be good in DevOps?
https://landing.google.com/sre/sre-book/toc/index.html
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
It’s about
• Searching for race factors —> Service Level Indicators
• Creating tactics —> Service Level Objectives
• Creating a strategy —> Service Level Agreement
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
Racing Factors —> Defining an indicator (SLI)
• pitstop
request latency
How long does it take to do a pitstop
How long does it take to return a response
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
Tactics —> Defining an objective (SLO)
not slower then 8 seconds
service x not longer then 0.1 seconds
• pitstop
request latency
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
Strategy —> Defining an agreement (SLA)
• 2 pitstops less then x seconds
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
Goals
Define the metrics
Create them in Micrometer
Save it to Prometheus
Visualize with Grafana
(Create the teams strategy)
(Preparing the car/race)
(The teams Pitwall)
Micrometer for the win!
But what is it?
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
SLF4J only for metrics
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
Reasons to use Micrometer
• No vendor lock-in
• It’s Pivotal VMWare Tanzu
• Easy integration in Spring Boot
• So also support in Cloud Foundry
• Simple to use
• You can choose your own database / monitoring system
• You can define your own set of metrics
• But you get a lot for free
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
Micrometer is included in Spring Boot 2 actuator
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
Extra dependency for Spring Boot 1.5.x
I<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-spring-legacy</artifactId>
</dependency>
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
And also for Micronaut
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
Pre-configured Bindings
• Instrumentions of:
• caches
• class loader
• garbage collection
• processor utilisation
• thread pools
• and more
https://i.ytimg.com/vi/eVpRNi5VEDo/maxresdefault.jpg
Demo time
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
Long Task Timer
https://i.pinimg.com/originals/fb/5b/98/fb5b98edf68000f44e89d6428a3e2c65.jpg
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
Timer
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
https://s1.cdn.autoevolution.com/images/news/gallery/red-bull-racing-beats-record-to-set-new-fastest-pit-stop-in-the-history-of-f1_2.jpg
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
Counter
https://www.wallpaperflare.com/static/467/219/735/mercedes-amg-f1-w07-hybrid-formula-1-testing-wallpaper.jpg
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
Gauge
https://cdn.24.co.za/files/Cms/General/d/4338/1678467a9d9149b983f38424014fb2c0.jpg
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
About security
• Please implement spring security
• Otherwise you will expose your endpoint to others
• And don’t forget to add it in your database config!
https://www.baeldung.com/spring-security-basic-authentication
https://egkatzioura.com/2020/05/07/spring-boot-and-micrometer-with-prometheus-part-6-securing-metrics/
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
Goals
Define the metrics
Create them in Micrometer
Save it to Prometheus
Visualize with Grafana
(Create the teams strategy)
(Preparing the car/race)
(The teams Pitwall)
@KoTurk77@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
Where to store the metrics?
Which database should I use?
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
Databases
• Prometheus
• Graphite
• Atlas
• KairosDB
Persistent or not persistent?
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
If you want to expose to prometheus
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>

@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
Or Graphite
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-graphite</artifactId>
</dependency>

@KoTurk77@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
How to configure your application
with prometheus
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
Goals
Define the metrics
Create them in Micrometer
Save it to Prometheus
Visualize with Grafana
(Create the teams strategy)
(Preparing the car/race)
(The teams Pitwall)
https://blog.purestorage.com/wp-content/uploads/2016/07/Pure-MBF1-Pitwall-v6.jpg
@KoTurk77@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
How to visualise the application metrics?
Which monitoring system to use?
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
Systems
• Grafana
• Datadog
• Dynatrace
• Instant
• WaveFront
• and many more
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
Let’s deep dive into Grafana
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
Long Task Timer (duration)
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
Timer (count)
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
Timer (max)
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
Gauge
@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
Bindings
@KoTurk77@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer
Title Text
All examples you can find at:
https://github.com/KoTurk/micrometer-race-demo
@KoTurk77
Thank you for listening

Monitoring your Spring Boot and Micronaut microservices with Micrometer

  • 1.
    Monitoring your SpringBoot and Micronaut microservices with Micrometer JCON2020# www.jcon.one Ko Turk Senior Java Developer Our Partners 2020:
  • 2.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer You’re part of a racing team
  • 4.
    Sounds silly right? Butwhat if we don’t have this kind of information?
  • 5.
    @KoTurk77@KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer But why don’t we (developers) think about proper monitoring?
  • 6.
    @KoTurk77@KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer Title Text https://formulaf1results.blogspot.com/2020/01/f1-crash-wallpaper.html Application X Application Y Backend (still driving but slow)
  • 7.
    @KoTurk77@KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer If that’s happening…..
  • 8.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer Of course you can log it but…..
  • 9.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer A log is an event that happened A metric is a measurement of the health of a system. https://www.sumologic.com/blog/logs-metrics-overview/
  • 10.
    @KoTurk77@KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer That’s where Micrometer comes in
  • 11.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer Introduction
  • 12.
  • 14.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer https://www.signifytechnology.com/blog/2019/09/whats-your-tech-stack
  • 15.
    Java 14Spring Boot Typescript Angular CloudFoundry Pipeline as code Micrometer
  • 16.
  • 17.
  • 18.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer UtrechtJUG
  • 20.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer Goals Define the metrics Create them in Micrometer Save it to Prometheus Visualize with Grafana (Create the teams strategy) (Preparing the car/race) (The teams Pitwall)
  • 21.
  • 22.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer What do we want to monitor?
  • 24.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer How to be good in DevOps?
  • 25.
  • 26.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer It’s about • Searching for race factors —> Service Level Indicators • Creating tactics —> Service Level Objectives • Creating a strategy —> Service Level Agreement
  • 27.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer Racing Factors —> Defining an indicator (SLI) • pitstop request latency How long does it take to do a pitstop How long does it take to return a response
  • 28.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer Tactics —> Defining an objective (SLO) not slower then 8 seconds service x not longer then 0.1 seconds • pitstop request latency
  • 29.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer Strategy —> Defining an agreement (SLA) • 2 pitstops less then x seconds
  • 30.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer Goals Define the metrics Create them in Micrometer Save it to Prometheus Visualize with Grafana (Create the teams strategy) (Preparing the car/race) (The teams Pitwall)
  • 32.
    Micrometer for thewin! But what is it?
  • 33.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer SLF4J only for metrics
  • 34.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer Reasons to use Micrometer • No vendor lock-in • It’s Pivotal VMWare Tanzu • Easy integration in Spring Boot • So also support in Cloud Foundry • Simple to use • You can choose your own database / monitoring system • You can define your own set of metrics • But you get a lot for free
  • 35.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer Micrometer is included in Spring Boot 2 actuator <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
  • 36.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer Extra dependency for Spring Boot 1.5.x I<dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-spring-legacy</artifactId> </dependency>
  • 37.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer And also for Micronaut
  • 38.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer Pre-configured Bindings • Instrumentions of: • caches • class loader • garbage collection • processor utilisation • thread pools • and more
  • 40.
  • 42.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer Long Task Timer
  • 43.
  • 44.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer Timer
  • 45.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer https://s1.cdn.autoevolution.com/images/news/gallery/red-bull-racing-beats-record-to-set-new-fastest-pit-stop-in-the-history-of-f1_2.jpg
  • 46.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer Counter
  • 47.
  • 48.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer Gauge
  • 49.
  • 50.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer About security • Please implement spring security • Otherwise you will expose your endpoint to others • And don’t forget to add it in your database config! https://www.baeldung.com/spring-security-basic-authentication https://egkatzioura.com/2020/05/07/spring-boot-and-micrometer-with-prometheus-part-6-securing-metrics/
  • 51.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer Goals Define the metrics Create them in Micrometer Save it to Prometheus Visualize with Grafana (Create the teams strategy) (Preparing the car/race) (The teams Pitwall)
  • 52.
    @KoTurk77@KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer Where to store the metrics? Which database should I use?
  • 53.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer Databases • Prometheus • Graphite • Atlas • KairosDB Persistent or not persistent?
  • 54.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer If you want to expose to prometheus <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-prometheus</artifactId> </dependency>

  • 55.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer Or Graphite <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-graphite</artifactId> </dependency>

  • 57.
    @KoTurk77@KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer How to configure your application with prometheus
  • 58.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer Goals Define the metrics Create them in Micrometer Save it to Prometheus Visualize with Grafana (Create the teams strategy) (Preparing the car/race) (The teams Pitwall)
  • 59.
  • 60.
    @KoTurk77@KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer How to visualise the application metrics? Which monitoring system to use?
  • 61.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer Systems • Grafana • Datadog • Dynatrace • Instant • WaveFront • and many more
  • 62.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer Let’s deep dive into Grafana
  • 63.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer Long Task Timer (duration)
  • 64.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer Timer (count)
  • 65.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer Timer (max)
  • 66.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer Gauge
  • 67.
    @KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer Bindings
  • 69.
    @KoTurk77@KoTurk77 The Battleof the IDEs #Devnexus@KoTurk77Monitoring your Spring Boot and Micronaut microservices with Micrometer Title Text
  • 71.
    All examples youcan find at: https://github.com/KoTurk/micrometer-race-demo @KoTurk77 Thank you for listening