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 teams 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 Graphana. Pretty interesting right?
In the demo I will show you how to create such applications using Micrometer, Spring Boot and Cloud Foundry as our platform. Ready to win this race with me? Jump in!
2. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
You’re part of a racing team
5. @KoTurk77@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
But why don’t we (developers) think about proper monitoring?
6. @KoTurk77@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
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@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
If that’s happening…..
8. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
Of course you can log it but…..
9. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
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@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
That’s where
Micrometer comes in
11. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
Introduction
14. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
https://www.signifytechnology.com/blog/2019/09/whats-your-tech-stack
18. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
UtrechtJUG
19.
20. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
Goals
Define the metrics
Create them in Micrometer
Save it to Prometheus
Visualize with Grafana
Deploy to Cloud Foundry
(Create the teams strategy)
(Preparing the car/race)
(The teams Pitwall)
(Let’s race)
22. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
What do we want to monitor?
23.
24. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
How to be good in DevOps?
26. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
It’s about
• Searching for race factors —> Service Level Indicators
• Creating tactics —> Service Level Objectives
• Creating a strategy —> Service Level Agreement
27. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
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 Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
Tactics —> Defining an objective (SLO)
not slower then 8 seconds
service x not longer then 0.1 seconds
• pitstop
request latency
29. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
Strategy —> Defining an agreement (SLA)
• 2 pitstops less then x seconds
30. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
Goals
Define the metrics
Create them in Micrometer
Save it to Prometheus
Visualize with Grafana
Deploy to Cloud Foundry
(Create the teams strategy)
(Preparing the car/race)
(The teams Pitwall)
(Let’s race)
33. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
SLF4J only for metrics
34. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
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 Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
Micrometer is included in Spring Boot 2 actuator
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
36. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
Extra dependency for Spring Boot 1.5.x
I<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-spring-legacy</artifactId>
</dependency>
37. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
And also for Micronaut
38. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
Pre-configured Bindings
• Instrumentions of:
• caches
• class loader
• garbage collection
• processor utilisation
• thread pools
• and more
43. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
Timer
44. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
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
45. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
Counter
49. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
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/
50. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
Goals
Define the metrics
Create them in Micrometer
Save it to Prometheus
Visualize with Grafana
Deploy to Cloud Foundry
(Create the teams strategy)
(Preparing the car/race)
(The teams Pitwall)
(Let’s race)
51. @KoTurk77@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
Where to store the metrics?
Which database should I use?
52. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
Databases
• Prometheus
• Graphite
• Atlas
• KairosDB
Persistent or not persistent?
53. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
If you want to expose to prometheus
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
54. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
Or Graphite
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-graphite</artifactId>
</dependency>
55.
56. @KoTurk77@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
How to configure your application
with prometheus
57. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
Goals
Define the metrics
Create them in Micrometer
Save it to Prometheus
Visualize with Grafana
Deploy to Cloud Foundry
(Create the teams strategy)
(Preparing the car/race)
(The teams Pitwall)
(Let’s race)
59. @KoTurk77@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
How to visualise the application metrics?
Which monitoring system to use?
60. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
Systems
• Grafana
• Datadog
• Dynatrace
• Instant
• WaveFront
• and many more
61. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
Let’s deep dive into Grafana
62. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
Long Task Timer (duration)
63. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
Timer (count)
64. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
Timer (max)
65. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
Gauge
66. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
Bindings
67.
68. @KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
Goals
Define the metrics
Create them in Micrometer
Save it to Prometheus
Visualize with Grafana
Deploy to Cloud Foundry
(Create the teams strategy)
(Preparing the car/race)
(The teams Pitwall)
(Let’s race)
69. @KoTurk77@KoTurk77 The Battle of the IDEs #Devnexus@KoTurk77Controlling your race with Micrometer, Spring Boot and Cloud Foundry
Title Text
70.
71. All examples you can find at:
https://github.com/KoTurk/micrometer-race-demo
@KoTurk77
Thank you for listening