Slide 1

Slide 1 text

Michael Simons, INNOQ @rotnroll666 MICROMETER:
 NEW INSIGHTS INTO YOUR SPRING BOOT APPLICATION

Slide 2

Slide 2 text

2 Micrometer: New insights into your Spring Boot application / @rotnroll666 @rotnroll666 Michael Simons
 Senior Consultant at INNOQ Deutschland GmbH • First Spring project 2009 (Spring 3) • First Spring Boot project early 2014 • Writes about Java, Spring and architecture on info.michael-simons.eu • Bestselling German book on Spring Boot 2 (springbootbuch.de) • Rants about stuff as @rotnroll666 on Twitter

Slide 3

Slide 3 text

Ways to observe a system 3 Micrometer: New insights into your Spring Boot application / @rotnroll666 • Logging • Tracing • Metrics

Slide 4

Slide 4 text

4 Micrometer: New insights into your Spring Boot application / @rotnroll666 Micrometer • New project by Pivotal • „Like SLF4J but for metrics“ • Vendor-neutral application metrics facade

Slide 5

Slide 5 text

How to get Micrometer into Spring Boot? 5 Micrometer: New insights into your Spring Boot application / @rotnroll666 org.springframework.boot spring-boot-starter-actuator

Slide 6

Slide 6 text

How to get Micrometer into Spring Boot? 5 Micrometer: New insights into your Spring Boot application / @rotnroll666 http://localhost:8080/metrics

Slide 7

Slide 7 text

{ "mem": 664619, "mem.free": 327742, "instance.uptime": 602975, "uptime": 606611, "systemload.average": 3.19677734375, "heap.committed": 596480, "heap.init": 262144, "heap.used": 268737, "heap": 3728384, "nonheap.committed": 69472, "nonheap.init": 2496, "nonheap.used": 68142, "nonheap": 0, "threads.totalStarted": 101, "threads": 29, "datasource.primary.active": 0, "datasource.primary.usage": 0.0, "gauge.response.metrics": 2.0, "gauge.response.motd": 3.0, "gauge.response.star-star.favicon.ico": 8.0, "counter.status.200.star-star.favicon.ico": 1, "counter.status.200.metrics": 4, "counter.status.200.mine": 1008 } How to get Micrometer into Spring Boot? 5 Micrometer: New insights into your Spring Boot application / @rotnroll666 http://localhost:8080/metrics/counter.status.200.metrics „Drill down“ ie.

Slide 8

Slide 8 text

That changes a lot with Spring Boot 2 6 Micrometer: New insights into your Spring Boot application / @rotnroll666 org.springframework.boot spring-boot-starter-parent 2.0.1.RELEASE

Slide 9

Slide 9 text

That changes a lot with Spring Boot 2 6 Micrometer: New insights into your Spring Boot application / @rotnroll666 curl -v localhost:8080/metrics * Trying 127.0.0.1... * TCP_NODELAY set * Connected to localhost (127.0.0.1) port 8080 (#0) > GET /metrics HTTP/1.1 > Host: localhost:8080 > User-Agent: curl/7.54.0 > Accept: */* > < HTTP/1.1 404 < Content-Type: application/json;charset=UTF-8 < Transfer-Encoding: chunked < Date: Wed, 02 May 2018 20:26:59 GMT < * Connection #0 to host localhost left intact {"timestamp":"2018-05-02T20:26:59.437+0000","status":404,"error":"Not Found","message":"No message available","path":"/metrics"}%

Slide 10

Slide 10 text

That changes a lot with Spring Boot 2 6 Micrometer: New insights into your Spring Boot application / @rotnroll666 management.endpoints.web.exposure.include = *

Slide 11

Slide 11 text

That changes a lot with Spring Boot 2 6 Micrometer: New insights into your Spring Boot application / @rotnroll666 curl -v localhost:8080/actuator/metrics * Trying ::1... * TCP_NODELAY set * Connected to localhost (::1) port 8080 (#0) > GET /actuator/metrics HTTP/1.1 > Host: localhost:8080 > User-Agent: curl/7.54.0 > Accept: */* > < HTTP/1.1 200 < Content-Type: application/vnd.spring-boot.actuator.v2+json;charset=UTF-8 < Transfer-Encoding: chunked < Date: Wed, 02 May 2018 20:34:36 GMT < * Connection #0 to host localhost left intact {"names": ["process.cpu.usage","jvm.memory.max","jvm.gc.pause","jvm.buffer.memory.used""tom cat.threads.current"]}%

Slide 12

Slide 12 text

What happened to the nice format? ! 7 Micrometer: New insights into your Spring Boot application / @rotnroll666 { "names": [ "jvm.buffer.memory.used", "jvm.memory.used", "jvm.memory.committed", "jdbc.connections.min", "hikaricp.connections.usage", "http.server.requests", "jvm.gc.max.data.size", "system.cpu.count", "tomcat.servlet.request.max", "hikaricp.connections.usage.percentile", "jdbc.connections.max", "tomcat.sessions.active.current", "system.cpu.usage", "jvm.threads.live", "jvm.classes.loaded", "jvm.classes.unloaded", "jvm.threads.peak", "tomcat.threads.current", "tomcat.global.request", "hikaricp.connections.creation", "jvm.gc.memory.promoted", "tomcat.sessions.rejected", "tomcat.sessions.alive.max" ] }

Slide 13

Slide 13 text

Now we have „real“ drill down… 8 Micrometer: New insights into your Spring Boot application / @rotnroll666 curl localhost:8080/actuator/metrics/http.server.requests | python -m json.tool { "name": "http.server.requests", "measurements": [ { "statistic": "COUNT", "value": 509.0 }, { "statistic": "MAX", "value": 0.012536956 } ], "availableTags": [ { "tag": "method", "values": [ "GET" ] }, { "tag": "uri", "values": [ "/mine", "/actuator/metrics/{requiredMetricName}" ] } ] }

Slide 14

Slide 14 text

Dimensions all the way 9 Micrometer: New insights into your Spring Boot application / @rotnroll666 curl localhost:8080/actuator/metrics/http.server.requests\?tag\=status:200\&tag\=uri:/mine | \ python -m json.tool { "name": "http.server.requests", "measurements": [ { "statistic": "COUNT", "value": 500.0 }, { "statistic": "MAX", "value": 0.0 } ], "availableTags": [ { "tag": "method", "values": [ "GET" ] } ] }

Slide 15

Slide 15 text

Core concepts 10 Micrometer: New insights into your Spring Boot application / @rotnroll666

Slide 16

Slide 16 text

Core concepts 11 Micrometer: New insights into your Spring Boot application / @rotnroll666 • Dimensionality • Registries • Meters • An SPI for registries

Slide 17

Slide 17 text

Dimensionality 12 Micrometer: New insights into your Spring Boot application / @rotnroll666 • A taxonomy: Hierarchical metrics • Works fine for a limited amount of information • host-xyz.counter.status. 200.mine is still fine, but… • Patterns for dashboards etc. get out of hands, blind to new taxonomies counter status 201 mine instance region cloud

Slide 18

Slide 18 text

From taxonomy to folksonomy 13 Micrometer: New insights into your Spring Boot application / @rotnroll666 • Classification system based on tags • Term from around 2004 • Advantages according to Wikipedia • Reflection of the users vocabulary • Flexible • Multidimensional • Tags are key/value pairs as dimension of a metric

Slide 19

Slide 19 text

Creating tags 14 Micrometer: New insights into your Spring Boot application / @rotnroll666 • Either as global common tags or • on the metrics themselves Timer.builder("presentation.slide.timer") .description("This is a timer.") .tags( "conference", "Spring I/O", "place", "Barcelona" ) .register(meterRegistry);

Slide 20

Slide 20 text

Creating tags 14 Micrometer: New insights into your Spring Boot application / @rotnroll666 • Either as global common tags or • on the metrics themselves Gauge.builder("jvm.memory.used", Runtime.getRuntime(), r -> r.totalMemory() - r.freeMemory()) .tag("host", "chronos") .tag("region", "my-desk") .register(meterRegistry);

Slide 21

Slide 21 text

Registries

Slide 22

Slide 22 text

Registries 16 Collect, store and export metrics • Simple registry Micrometer: New insights into your Spring Boot application / @rotnroll666 MeterRegistry registry = new SimpleMeterRegistry();

Slide 23

Slide 23 text

Registries 16 Collect, store and export metrics • Simple registry • Composite registries Micrometer: New insights into your Spring Boot application / @rotnroll666 CompositeMeterRegistry composite = new CompositeMeterRegistry(); Counter counter = composite.counter("counter"); counter.increment(); // noop SimpleMeterRegistry simple = new SimpleMeterRegistry(); composite.add(simple); counter.increment(); // now stuff happens

Slide 24

Slide 24 text

Registries 16 Collect, store and export metrics • Simple registry • Composite registries • The global registry Micrometer: New insights into your Spring Boot application / @rotnroll666 MeterRegistry registry = Metrics.globalRegistry;

Slide 25

Slide 25 text

Registries 16 Collect, store and export metrics • Simple registry • Composite registries • The global registry Micrometer: New insights into your Spring Boot application / @rotnroll666 The global registry is special • An empty composite by default • Can a be a source of meters everywhere • One has to add a simple registry • Or let Spring Boot wire up its registry to it MeterRegistry registry = Metrics.globalRegistry;

Slide 26

Slide 26 text

Metrics: Measurement of meters over time 17 Micrometer: New insights into your Spring Boot application / @rotnroll666

Slide 27

Slide 27 text

Counter

Slide 28

Slide 28 text

Gauges

Slide 29

Slide 29 text

Timer

Slide 30

Slide 30 text

Demo

Slide 31

Slide 31 text

What’s next?

Slide 32

Slide 32 text

Three different kinds of metrics 23 Micrometer: New insights into your Spring Boot application / @rotnroll666 • System metrics • Application metrics • Domain metrics (or KPIs)

Slide 33

Slide 33 text

System metrics 24 Micrometer: New insights into your Spring Boot application / @rotnroll666 • Classloader • JVM Memory usage • JVM Garbage Collector • JVM Thread usage • Processor usage new ClassLoaderMetrics().bindTo(registry); new JvmMemoryMetrics().bindTo(registry); new JvmGcMetrics().bindTo(registry); new ProcessorMetrics().bindTo(registry); new JvmThreadMetrics().bindTo(registry);

Slide 34

Slide 34 text

Application metrics with Spring Boot 25 Micrometer: New insights into your Spring Boot application / @rotnroll666 • Spring MVC • Spring WebFlux • RestTemplate (HTTP Client) • Spring Integration • Spring MQ

Slide 35

Slide 35 text

Domain metrics (or KPIs) 26 Micrometer: New insights into your Spring Boot application / @rotnroll666 • What you get: A nice API to add YOUR metrics • Bring your own metrics • „How many products did I sell the last hour?“ • „How long did the booking process take?“ • „How many pending customers are there?“

Slide 36

Slide 36 text

Demo

Slide 37

Slide 37 text

Monitoring

Slide 38

Slide 38 text

Where to store this? 29 Micrometer: New insights into your Spring Boot application / @rotnroll666

Slide 39

Slide 39 text

Supported dimensional monitoring systems 30 Micrometer: New insights into your Spring Boot application / @rotnroll666 • Atlas • Datadog • Datadog StatsD • Influx • Prometheus • SignalFx • Telegraf StatsD • Wavefront

Slide 40

Slide 40 text

Supported hierarchical monitoring systems 31 Micrometer: New insights into your Spring Boot application / @rotnroll666 • Graphite • Ganglia • JMX • Etsy StatsD

Slide 41

Slide 41 text

How to store metrics? 32 Micrometer: New insights into your Spring Boot application / @rotnroll666

Slide 42

Slide 42 text

Push model 33 Micrometer: New insights into your Spring Boot application / @rotnroll666 • Atlas • Datadog • Graphite • Ganglia • Influx • JMX • all StatsD flavors • SignalFx • Wavefront

Slide 43

Slide 43 text

Poll model 34 Micrometer: New insights into your Spring Boot application / @rotnroll666 • Prometheus scrape_configs: - job_name: 'reactive-java-chain' metrics_path: '/actuator/prometheus' static_configs: - targets: ['localhost:8080'] - job_name: 'reactive-kotlin-chain' metrics_path: '/actuator/prometheus' static_configs: - targets: ['localhost:8090']

Slide 44

Slide 44 text

Demo

Slide 45

Slide 45 text

36 • Micrometer has more features • Histograms • SLAs • Filter and transformer • Micrometer is not specific to Spring Boot 2 • Can be used stand-alone • Can also be used with Spring Boot 1 Micrometer: New insights into your Spring Boot application / @rotnroll666 Closing notes io.micrometer micrometer-spring-legacy ${micrometer.version}

Slide 46

Slide 46 text

37 • Demo: 
 github.com/michael-simons/blockchain- playground
 (Contains talk as welk) • Slides: speakerdeck.com/michaelsimons • Excellent Webinar by Jon Schneider:
 https://www.brighttalk.com/webcast/ 14893/316569 • Spring Boot Buch (German)
 @SpringBootBuch // springbootbuch.de Micrometer: New insights into your Spring Boot application / @rotnroll666 Ressources

Slide 47

Slide 47 text

Picture sources 38 • Meter: https://unsplash.com/photos/zPZ9vqqDNBA • Library: https://unsplash.com/photos/xLhKkk2tKkA • Tally counter: https://www.flickr.com/photos/jauladeardilla/5768409603/ • Gauge: https://unsplash.com/photos/HM731qUoUas • Timer: https://unsplash.com/photos/rBPOfVqROzY • Demo: 
 https://unsplash.com/photos/Uduc5hJX2Ew
 https://unsplash.com/photos/FlPc9_VocJ4
 https://unsplash.com/photos/gp8BLyaTaA0 • Monitoring
 https://unsplash.com/photos/mcSDtbWXUZU Micrometer: New insights into your Spring Boot application / @rotnroll666