Save 37% off PRO during our Black Friday Sale! »

Micrometer入門 #javaq / introduce-to-micrometer

Micrometer入門 #javaq / introduce-to-micrometer

Javaコミュ@福岡 勉強会1910 での発表資料です
https://javaq.connpass.com/event/147444/

0a98ad166f9cdf8d27d92c37438c6e9d?s=128

Manabu Matsuzaki

October 08, 2019
Tweet

Transcript

  1. Micrometerೖ໳ Javaίϛϡˏ෱Ԭ ษڧձ1910 2019/10/08 @matsumana

  2. Self Introduction • Nameɿ Manabu Matsuzaki • Work atɿ LINE

    Fukuoka Corporation • Roleɿ SRE • Twitterɿ @matsumana
  3. Agenda • Micrometerೖ໳ • MicrometerͷओཁͳMeterͱTag • MicrometerΛ࢖͏ • Micrometerͷ֤छMeterΛ࢖ͬͯࣗ෼ͰϝτϦΫεΛه࿥͢Δ •

    Spring BootΞϓϦͰ࢖͏ • Binder • Demo
  4. ͜ͷࢿྉ͸ҎԼͷόʔδϣϯΛݩʹ࡞੒͍ͯ͠·͢ • Micrometer: 1.3.0 (LTS) • https://github.com/micrometer-metrics/micrometer/releases • Spring Boot:

    2.2.0 RC1 • https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.2- Release-Notes • Armeria: 0.94.0 (Micrometerͷ࢖͍ํͷαϯϓϧͱͯ͠঺հ͠·͢) • https://github.com/line/armeria/releases
  5. Micrometerͱ͸ʁ

  6. https://micrometer.io/

  7. Micrometer͕αϙʔτ͍ͯ͠Δ ϞχλϦϯάγεςϜ • Datadog • Prometheus • Elasticsearch • etc…

  8. MicrometerͷओཁͳMeterͱTag

  9. ओཁͳMeter આ໌ Counter ୯७૿Ճ͢ΔϝτϦΫε ྫʣग़ྗͨ͠logͷճ਺ Gauge ஋্͕Լ͢ΔϝτϦΫε ྫʣin-flight(ݱࡏॲཧத)ͷϦΫΤετ਺ Timer ϝιουͷॲཧ࣌ؒܭଌͳͲ

    LongTaskTimer ͕͔͔࣌ؒΔॲཧͷ࣌ؒܭଌ DistributionSummary Πϕϯτͷαϯϓϧ෼෍ ྫʣhttpͷrequest/responseαΠζ
  10. TagͰϝτϦΫεʹ৘ใΛ෇Ճ͢Δ • Tag͸key-valueͷϖΞ • 1ͭͷϝτϦΫεʹରͯ͠ෳ਺ͷTagΛ෇ՃͰ͖Δ • Tag͕࣮ࡍͷϝτϦΫεͰͲ͏ѻΘΕΔ͔͸ɺ
 ࣗ෼͕࢖͏ϞχλϦϯάγεςϜ࣍ୈ

  11. TagͰϝτϦΫεʹ৘ใΛ෇Ճ͢Δ • Πϝʔδɿ TagΛαϙʔτ͢ΔϞχλϦϯάγεςϜ TagΛαϙʔτ͠ͳ͍ϞχλϦϯάγεςϜ http_server_requests{uri=“/foo”, status=“200"} 10 http_server_requests_foo_200 10

    http_server_requests{uri=“/foo”, status=“500"} 2 http_server_requests_foo_500 20 http_server_requests{uri=“/bar”, status=“200"} 21 http_server_requests_bar_200 21 http_server_requests{uri=“/bar”, status=“500"} 4 http_server_requests_bar_500 4
  12. Tag͕࢖͑Δ Tag͕࢖͑ͳ͍ AppOptics, Atlas, Azure Monitor, Cloudwatch, Datadog, Datadog StatsD,

    Dynatrace, Elastic, Humio, Influx, KairosDB, New Relic, Prometheus, SignalFx, Sysdig StatsD, Telegraf StatsD, Wavefront Graphite, Ganglia, JMX, Etsy StatsD ֤ϞχλϦϯάγεςϜͷTagαϙʔτ https://micrometer.io/docs/concepts#_supported_monitoring_systems
  13. ϝτϦΫεͱTagͷ໋໊نଇ • ϝτϦΫεͱLabelͷ໊લ͸େࣄͰ͢ • MicrometerͷυΩϡϝϯτ • Naming meters:
 https://micrometer.io/docs/concepts#_naming_meters •

    PrometheusͷυΩϡϝϯτ • Metric and label naming:
 https://prometheus.io/docs/practices/naming/
  14. MicrometerΛ࢖͏

  15. Micrometerͷ֤छMeterΛ࢖ͬͯ ࣗ෼ͰϝτϦΫεΛه࿥͢Δ

  16. αϯϓϧϓϩάϥϜ • Micrometerιʔεrepoʹ͋ΔαϯϓϧϓϩάϥϜ • https://github.com/micrometer-metrics/micrometer/tree/v1.3.0/ samples/micrometer-samples-core/src/main/java/io/micrometer/ core/samples • CounterSample.java •

    GaugeSample.java • TimerSample.java
  17. αϯϓϧϓϩάϥϜ • Micrometerͷ࢖͍ํ͸Armeria΋ࢀߟʹͳΓ·͢ • ྫʣϦΫΤετ/ϨεϙϯεͷϝτϦΫε • https://github.com/line/armeria/blob/armeria-0.94.0/core/src/main/java/com/linecorp/ armeria/internal/metric/RequestMetricSupport.java#L241-L247 • https://github.com/line/armeria/blob/armeria-0.94.0/core/src/main/java/com/linecorp/

    armeria/common/logging/DefaultRequestLog.java • ϦΫΤετ੒ޭ਺ɺϦΫΤετΤϥʔ਺ (Counter) • ϦΫΤετॲཧ࣌ؒ (Timer) • ϦΫΤεταΠζɺϨεϙϯεαΠζ (DistributionSummary)
  18. Spring BootΞϓϦͰ࢖͏

  19. ΞϓϦέʔγϣϯઃఆ (Must) • ActuatorΛґଘϥΠϒϥϦʹ௥Ճ
 org.springframework.boot:spring-boot-starter-actuator • ࣗ෼͕࢖͏ϞχλϦϯάγεςϜ༻ͷґଘϥΠϒϥϦ΋௥Ճ • Prometheusͷ৔߹: io.micrometer:micrometer-registry-prometheus

    • Datadogͷ৔߹: io.micrometer:micrometer-registry-datadog
  20. ΞϓϦέʔγϣϯઃఆ (Optional) • Prometheusͷ৔߹ɺΞϓϦέʔγϣϯଆʹPrometheusαʔό͕ Scrape͢ΔEndpoint͕ඞཁɻ • application.yml(or application.properties)ʹઃఆΛߦ͏ • management.endpoints.web.exposure.includeʹprometheusΛ௥Ճ


    ྫʣ
 management.endpoints.web.exposure.include=info, health, prometheus
  21. ΞϓϦέʔγϣϯઃఆʢ͓͢͢Ίʣ • ݸਓతʹɺҎԼ΋ઃఆ͢ΔࣄΛ͓͢͢Ί • URIຖͷϨΠςϯγͷϝτϦΫε
 management.metrics.distribution.percentiles.http.server.requests

  22. ؔ࿈υΩϡϝϯτͱࢀߟϒϩά • Spring Boot Actuator: Production-ready Features
 https://docs.spring.io/spring-boot/docs/2.2.0.RC1/reference/html/ production-ready-features.html •

    Spring BootΞϓϦͷϝτϦΫεΛMicrometerͰऩू͢Δ
 https://matsumana.info/blog/2018/05/23/collect-spring-boot-app- metrics-with-micrometer/ • ϨΠςϯγʔΛܭࢉ͢Δٕज़ͷ࿩
 https://engineering.linecorp.com/ja/blog/latency-calculation-techniques/
  23. Binder

  24. Binderͱ͸ʁ • ϞχλϦϯάର৅(JVM/APαʔό/ϥΠϒϥϦͳͲ)ͱMicrometerͱͷͭͳ͗໾ • ϞχλϦϯάର৅ࣗ਎͕͍࣋ͬͯΔϝτϦΫεΛMicrometerܦ༝ͰϞχλϦ ϯάγεςϜʹૹΔࣄ͕Ͱ͖Δ
 • Micrometerͷඪ४Binder
 https://github.com/micrometer-metrics/micrometer/tree/v1.3.0/micrometer- core/src/main/java/io/micrometer/core/instrument/binder

    • JVMɺTomcatɺJettyɺLogbackɺCaffeineɺetc…
  25. Binderͱ͸ʁ • ྫ͑͹ɺJVMؔ࿈ͷϝτϦΫε͸ҎԼ • https://github.com/micrometer-metrics/micrometer/tree/v1.3.0/ micrometer-core/src/main/java/io/micrometer/core/instrument/binder/jvm • JvmGcMetrics.java • JvmMemoryMetrics.java

    • JvmThreadMetrics.java • ClassLoaderMetrics.java
  26. DEMO • αϯϓϧΞϓϦ • https://github.com/matsumana/micrometer-example • DatadogʹϝτϦΫεΛอଘ͢Δ • PrometheusʹϝτϦΫεΛอଘͯ͠GrafanaͰՄࢹԽ͢Δ •

    JVMϝτϦΫεͷμογϡϘʔυ • HikariCPϝτϦΫεͷμογϡϘʔυ
  27. ·ͱΊ • MicrometerͷओཁͳMeterͱTagʹ͍ͭͯઆ໌͠·ͨ͠ • MeterΛ࢖ͬͯϝτϦΫεΛه࿥͢Δํ๏ʹ͍ͭͯઆ໌͠·ͨ͠ • Binderʹ͍ͭͯઆ໌͠·ͨ͠ • DatadogɺPrometheusͷσϞΛ͓ݟͤ͠·ͨ͠ •

    JVMͱHikariCPͷϝτϦΫεΛGrafanaͰՄࢹԽͯ͠Έ·ͨ͠
  28. Thank you :)