Abstract "Imagine that you’re part of a (car) race team. You’re the one behind the screens to control the race and make some tough decisions (like changing the team's strategy).
But you don’t have the insights (or metrics) about your car, opponents or even the weather. Sounds painful right? But why are we making this mistake when building our software? Why don’t we implement metrics by default?
SLFf4J logging is one side of the story, but we also need to know our application health. That’s where Micrometer comes in! It’s a library which you can use to define your own custom metrics, like:
-timers (to check the performance of your microservices)
-counters (to check how many times a certain event is occurring)
-gauges (to check the current value of a variable)
-and many more
These metrics are exposed by REST endpoints (JSON) together with Spring Boot actuator, which can be saved into a database like Prometheus or Graphite. And to visualize the data you can use a tool like Grafana. Pretty interesting right?
In the demo (live coding!) Ko Turk will show you how to create such applications using Micrometer, Spring Boot and Cloud Foundry as our platform. Ready to win this race with him? Jump in!"
5. @KoTurk77
@KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
But why don’t we (developers) think about proper monitoring?
6. @KoTurk77
@KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
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 Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
If that’s happening…..
8. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
Of course you can log it but…..
9. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
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 Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
That’s where
Micrometer comes in
11. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
Introduction
16. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
https://www.signifytechnology.com/blog/2019/09/whats-your-tech-stack
19. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
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)
25. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
It’s about
• Searching for race factors —> Service Level Indicators
• Creating tactics —> Service Level Objectives
• Creating a strategy —> Service Level Agreement
26. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
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
27. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
Tactics —> Defining an objective (SLO)
Shouldn’t take more than 8 seconds
Shouldn’t be taking more than 0.1 seconds
• pitstop
request latency
28. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
Strategy —> Defining an agreement (SLA)
• 2 pitstops less then 8 seconds
99,9 % of all requests less than 0.1 seconds
29. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
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. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
SLF4J only for metrics
33. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
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
34. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
Micrometer is included in Spring Boot 2 actuator
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
35. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
Extra dependency for Spring Boot 1.5.x
I<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-spring-legacy</artifactId>
</dependency>
36. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
And also for Micronaut
37. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
Pre-configured Bindings
• Instrumentions of:
• caches
• class loader
• garbage collection
• processor utilisation
• thread pools
• and more
42. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
Timer
43. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
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
44. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
Histograms
45. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
46. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
47. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
Counter
51. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
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/
52. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
Sensitive data (!)
• Disable endpoints you don’t need
53. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
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)
54. @KoTurk77
@KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
Where to store the metrics?
Which database should I use?
55. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
Databases
• Prometheus
• Graphite
• Atlas
• KairosDB
Persistent or not persistent?
56. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
If you want to expose to prometheus
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
57. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
Or Graphite
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-graphite</artifactId>
</dependency>
58.
59. @KoTurk77
@KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
How to configure your application
with prometheus
60. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
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)
62. @KoTurk77
@KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
How to visualise the application metrics?
Which monitoring system to use?
63. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
Systems
• Grafana
• Datadog
• Dynatrace
• Instant
• WaveFront
• and many more
64. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
Let’s deep dive into Grafana
65. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
Long Task Timer (duration)
66. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
Timer (count)
67. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
Timer (max)
68. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
Gauge
69. @KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
Bindings
70.
71. @KoTurk77
@KoTurk77 The Battle of the IDEs #Devnexus
@KoTurk77
Controlling your race with Micrometer and Spring Boot (2.x)
Title Text
72.
73. All examples you can find at:
https://github.com/KoTurk/
@KoTurk77
Thank you for listening