Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

Self Introduction • Nameɿ Manabu Matsuzaki • Work atɿ LINE Fukuoka Corporation • Roleɿ SRE • Twitterɿ @matsumana

Slide 3

Slide 3 text

Agenda • Micrometerೖ໳ • MicrometerͷओཁͳMeterͱTag • MicrometerΛ࢖͏ • Micrometerͷ֤छMeterΛ࢖ͬͯࣗ෼ͰϝτϦΫεΛه࿥͢Δ • Spring BootΞϓϦͰ࢖͏ • Binder • Demo

Slide 4

Slide 4 text

͜ͷࢿྉ͸ҎԼͷόʔδϣϯΛݩʹ࡞੒͍ͯ͠·͢ • 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

Slide 5

Slide 5 text

Micrometerͱ͸ʁ

Slide 6

Slide 6 text

https://micrometer.io/

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

MicrometerͷओཁͳMeterͱTag

Slide 9

Slide 9 text

ओཁͳMeter આ໌ Counter ୯७૿Ճ͢ΔϝτϦΫε ྫʣग़ྗͨ͠logͷճ਺ Gauge ஋্͕Լ͢ΔϝτϦΫε ྫʣin-flight(ݱࡏॲཧத)ͷϦΫΤετ਺ Timer ϝιουͷॲཧ࣌ؒܭଌͳͲ LongTaskTimer ͕͔͔࣌ؒΔॲཧͷ࣌ؒܭଌ DistributionSummary Πϕϯτͷαϯϓϧ෼෍ ྫʣhttpͷrequest/responseαΠζ

Slide 10

Slide 10 text

TagͰϝτϦΫεʹ৘ใΛ෇Ճ͢Δ • Tag͸key-valueͷϖΞ • 1ͭͷϝτϦΫεʹରͯ͠ෳ਺ͷTagΛ෇ՃͰ͖Δ • Tag͕࣮ࡍͷϝτϦΫεͰͲ͏ѻΘΕΔ͔͸ɺ
 ࣗ෼͕࢖͏ϞχλϦϯάγεςϜ࣍ୈ

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

ϝτϦΫεͱTagͷ໋໊نଇ • ϝτϦΫεͱLabelͷ໊લ͸େࣄͰ͢ • MicrometerͷυΩϡϝϯτ • Naming meters:
 https://micrometer.io/docs/concepts#_naming_meters • PrometheusͷυΩϡϝϯτ • Metric and label naming:
 https://prometheus.io/docs/practices/naming/

Slide 14

Slide 14 text

MicrometerΛ࢖͏

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

αϯϓϧϓϩάϥϜ • 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

Slide 17

Slide 17 text

αϯϓϧϓϩάϥϜ • 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)

Slide 18

Slide 18 text

Spring BootΞϓϦͰ࢖͏

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

ΞϓϦέʔγϣϯઃఆ (Optional) • Prometheusͷ৔߹ɺΞϓϦέʔγϣϯଆʹPrometheusαʔό͕ Scrape͢ΔEndpoint͕ඞཁɻ • application.yml(or application.properties)ʹઃఆΛߦ͏ • management.endpoints.web.exposure.includeʹprometheusΛ௥Ճ
 ྫʣ
 management.endpoints.web.exposure.include=info, health, prometheus

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

ؔ࿈υΩϡϝϯτͱࢀߟϒϩά • 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/

Slide 23

Slide 23 text

Binder

Slide 24

Slide 24 text

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…

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

DEMO • αϯϓϧΞϓϦ • https://github.com/matsumana/micrometer-example • DatadogʹϝτϦΫεΛอଘ͢Δ • PrometheusʹϝτϦΫεΛอଘͯ͠GrafanaͰՄࢹԽ͢Δ • JVMϝτϦΫεͷμογϡϘʔυ • HikariCPϝτϦΫεͷμογϡϘʔυ

Slide 27

Slide 27 text

·ͱΊ • MicrometerͷओཁͳMeterͱTagʹ͍ͭͯઆ໌͠·ͨ͠ • MeterΛ࢖ͬͯϝτϦΫεΛه࿥͢Δํ๏ʹ͍ͭͯઆ໌͠·ͨ͠ • Binderʹ͍ͭͯઆ໌͠·ͨ͠ • DatadogɺPrometheusͷσϞΛ͓ݟͤ͠·ͨ͠ • JVMͱHikariCPͷϝτϦΫεΛGrafanaͰՄࢹԽͯ͠Έ·ͨ͠

Slide 28

Slide 28 text

Thank you :)