$30 off During Our Annual Pro Sale. View Details »

Micrometer: New insights into your Spring Boot application

Micrometer: New insights into your Spring Boot application

Michael Simons

May 25, 2018
Tweet

More Decks by Michael Simons

Other Decks in Programming

Transcript

  1. Michael Simons, INNOQ
    @rotnroll666
    MICROMETER:

    NEW INSIGHTS INTO YOUR SPRING BOOT APPLICATION

    View Slide

  2. 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

    View Slide

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

    View Slide

  4. 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

    View Slide

  5. How to get Micrometer into Spring Boot?
    5
    Micrometer: New insights into your Spring Boot application / @rotnroll666

    org.springframework.boot
    spring-boot-starter-actuator

    View Slide

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

    View Slide

  7. {
    "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.

    View Slide

  8. 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


    View Slide

  9. 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"}%

    View Slide

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

    View Slide

  11. 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"]}%

    View Slide

  12. 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"
    ]
    }

    View Slide

  13. 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}"
    ]
    }
    ]
    }

    View Slide

  14. 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"
    ]
    }
    ]
    }

    View Slide

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

    View Slide

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

    View Slide

  17. 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

    View Slide

  18. 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

    View Slide

  19. 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);

    View Slide

  20. 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);

    View Slide

  21. Registries

    View Slide

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

    View Slide

  23. 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

    View Slide

  24. 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;

    View Slide

  25. 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;

    View Slide

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

    View Slide

  27. Counter

    View Slide

  28. Gauges

    View Slide

  29. Timer

    View Slide

  30. Demo

    View Slide

  31. What’s next?

    View Slide

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

    View Slide

  33. 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);

    View Slide

  34. 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

    View Slide

  35. 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?“

    View Slide

  36. Demo

    View Slide

  37. Monitoring

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  43. 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']

    View Slide

  44. Demo

    View Slide

  45. 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}

    View Slide

  46. 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

    View Slide

  47. 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

    View Slide