SlideShare a Scribd company logo
1 of 47
Download to read offline
1
Spring Boot Actuator 2.0 &
Micrometer
2018-03-27
Toshiaki Maki (@making / tmaki@pivotal.io)
Who am I ?
2
Toshiaki Maki (@making) https://blog.ik.am
Sr. Solutions Architect @Pivotal Japan
Spring / Cloud Foundry / Concourse / Kubernetes
" Spring Boot 2": https://note.ik.am (not free!)
What' new in Spring Boot 2
X
• Infrastructure Update (Spring 5, Tomcat 8.5, Jetty
9.4, Hibernete 5.3, HikariCP as a default CP)
• Starters for reactive projects
• Reactive web test support
• new OAuth 2 support
• explicit Spring Security configurations
• Actuator refactoring / Micrometer support
• Kotlin support
Agenda
3
• Spring Boot Actuator 2
• Micrometer
• Micrometer
• Histograms and percentiles
• Micrometer API
Spring Boot Actuator 2
Spring Boot Actuator
5
Additional features to help you monitor and manage
your application in production.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Supported Endpoints
6
• auditevents
• beans
• conditions
• configprops
• env
• flyway
• health
• httptrace
https://demo-micrometer.cfapps.io/actuator
https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html
• info
• loggers
• liquibase
• metrics
• mappings
• scheduledtasks
• sessions
• shutdown
• threaddump
• heapdump
• jolokia
• logfile
• prometheus
/actuator/*
•renamed
•added
Technology Support
7
Spring Boot Actuator 1.x Spring Boot Actuator 2.x
•Spring MVC •Spring MVC
•Spring WebFlux
•Jersey
How to enable endpoints
8
Default exposed endpoints are /info and /health.
management.endpoints.web.exposure.include=*
management.endpoints.web.exposure.include=info,health,env
All endpoints are not secured by default.
Secure endpoints (Spring MVC)
9
http.authorizeRequests()
.mvcMatchers("/actuator/health", "/actuator/info")
.permitAll()
.mvcMatchers("/actuator/**")

.hasRole("ACTUATOR")
.anyRequest()
.permitAll()
.and()
.httpBasic()
.and()...
Secure endpoints (Spring MVC)
9
http.authorizeRequests()
.mvcMatchers("/actuator/health", "/actuator/info")
.permitAll()
.mvcMatchers("/actuator/**")

.hasRole("ACTUATOR")
.anyRequest()
.permitAll()
.and()
.httpBasic()
.and()... spring.security.user.name=hoge
spring.security.user.password=foo
spring.security.user.roles=ACTUATOR
Secure endpoints (Spring MVC)
10
http.authorizeRequests()
.requestMatchers(EndpointRequest.to("health", "info"))
.permitAll()
.requestMatchers(EndpointRequest.toAnyEndpoint())

.hasRole("ACTUATOR")
.anyRequest()
.permitAll()
.and()
.httpBasic()
.and()...
Secure endpoints (Spring WebFlux)
11
http.authorizeExchange()
.matchers(EndpointRequest.to("health", "info"))
.permitAll()
.matchers(EndpointRequest.toAnyEndpoint())

.hasRole("ACTUATOR")
.anyExchange()
.permitAll()
.and()
.httpBasic()
.and()...
Health Check
12
management.endpoint.health.show-details=when_authorized
when authorized
Cloud Foundry Support
13 https://docs.spring.io/spring-boot/docs/2.0.x/reference/html/production-ready-cloudfoundry.html
Micrometer
Micrometer
15
Move to Micrometer
Think SLF4J, but for Metrics
Instrument without vendor lock-in:
• Prometheus
• Netflix Atlas
• Datadog
• InfluxDB
• ...
Multi-dementional metrics
https://micrometer.io/
Supported monitoring systems
16
Server polls Client pushes
Prometheus
Atlas, Datadog, Datadog StatsD,
Influx, SignalFx, Telegraf StatsD,
Wavefront, New Relic
Dimensional
Graphite, Ganglia, JMX, Etsy StatsD,
PCF Metrics 1.4
Hierarchical
push
poll
Prometheus
17
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
/actuator/prometheus
18
system_cpu_count 4.0
system_load_average_1m 1.64
jvm_memory_max_bytes{area="heap",id="PS Eden Space",}
1.05906176E8
jvm_memory_max_bytes{area="heap",id="PS Survivor Space",}
2.1495808E7
jvm_memory_max_bytes{area="heap",id="PS Old Gen",} 3.00941312E8
http_server_requests_seconds_count{exception="None",method="GET"
,status="200",uri="/hello",} 4469.0
http_server_requests_seconds_sum{exception="None",method="GET",s
tatus="200",uri="/hello",} 297.942920787
http_server_requests_seconds_max{exception="None",method="GET",s
tatus="200",uri="/hello",} 0.401581731
https://docs.spring.io/spring-boot/docs/2.0.x/reference/html/production-ready-metrics.html#production-ready-
metrics-meter
Prometheus
19
Grafana
20
On Cloud Foundry
21
@Bean
@Profile("cloud")
public MeterRegistryCustomizer meterRegistryCustomizer(
@Value("${vcap.application.name:}") String name,
@Value("${vcap.application.instance_id:}") String id) {
return registry -> registry.config()
.commonTags("cf_app_name", name,
"cf_app_instance_id", id);
}
On Cloud Foundry
22
system_cpu_count{cf_app_instance_id="31388366-...",cf_app_name="
demo-micrometer",}
} 4.0
system_load_average_1m{cf_app_instance_id="31388366-...",cf_app_
name="demo-micrometer",} 1.64
jvm_memory_max_bytes{cf_app_instance_id="31388366-...",cf_app_na
me="demo-micrometer",area="heap",id="PS Eden Space",}
1.05906176E8
jvm_memory_max_bytes{cf_app_instance_id="31388366-...",cf_app_na
me="demo-micrometer",area="heap",id="PS Survivor Space",}
2.1495808E7
jvm_memory_max_bytes{cf_app_instance_id="31388366-...",cf_app_na
me="demo-micrometer",area="heap",id="PS Old Gen",} 3.00941312E8
Datadog
23
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-datadog</artifactId>
</dependency>
management.metrics.export.datadog.api-key=YOUR-API-KEY
Datadog
24
PCF Metrics
25
Bind Metrics Forwarder Service
https://github.com/cloudfoundry/java-buildpack-metric-writer Use Metric Writer 2.4.0+ which comes with JBP 4.10+
Histograms and percentiles
Histogram
27
management.metrics.distribution.percentiles-
histogram.http.server.requests=true
Histogram in Prometheus
28
http_server_requests_seconds_bucket{...,uri="/hello",le="0.061516456",} 15646.0
http_server_requests_seconds_bucket{...,uri="/hello",le="0.067108864",} 15657.0
http_server_requests_seconds_bucket{...,uri="/hello",le="0.089478485",} 15679.0
http_server_requests_seconds_bucket{...,uri="/hello",le="0.111848106",} 15679.0
http_server_requests_seconds_bucket{...,uri="/hello",le="0.134217727",} 15680.0
http_server_requests_seconds_bucket{...,uri="/hello",le="0.156587348",} 15680.0
http_server_requests_seconds_bucket{...,uri="/hello",le="0.178956969",} 15680.0
http_server_requests_seconds_bucket{...,uri="/hello",le="0.20132659",} 15680.0
http_server_requests_seconds_bucket{...,uri="/hello",le="0.223696211",} 15680.0
http_server_requests_seconds_bucket{...,uri="/hello",le="0.246065832",} 15680.0
http_server_requests_seconds_bucket{...,uri="/hello",le="0.268435456",} 15680.0
http_server_requests_seconds_bucket{...,uri="/hello",le="0.357913941",} 15680.0
http_server_requests_seconds_bucket{...,uri="/hello",le="0.447392426",} 16475.0
The number of requests that took less than 0.447392426 sec.
Query percentiles in Prometheus
29
histogram_quantile(0.9,
sum(rate(http_server_requests_seconds_bucket{status="200"
}[5m])) by (app, uri, le))
https://prometheus.io/docs/prometheus/latest/querying/functions/#histogram_quantile()
SLA (Service Level Agreement)
30
management.metrics.distribution.sla.http.server.requests=
100ms, 200ms, 400ms
SLA in Prometheus
31
http_server_requests_seconds_bucket{...,uri="/hello",le="0.061516456",} 15646.0
http_server_requests_seconds_bucket{...,uri="/hello",le="0.067108864",} 15657.0
http_server_requests_seconds_bucket{...,uri="/hello",le="0.089478485",} 15679.0
http_server_requests_seconds_bucket{...,uri="/hello",le="0.1",} 15679.0
http_server_requests_seconds_bucket{...,uri="/hello",le="0.111848106",} 15679.0
http_server_requests_seconds_bucket{...,uri="/hello",le="0.134217727",} 15680.0
http_server_requests_seconds_bucket{...,uri="/hello",le="0.156587348",} 15680.0
http_server_requests_seconds_bucket{...,uri="/hello",le="0.178956969",} 15680.0
http_server_requests_seconds_bucket{...,uri="/hello",le="0.2",} 15680.0
http_server_requests_seconds_bucket{...,uri="/hello",le="0.20132659",} 15680.0
http_server_requests_seconds_bucket{...,uri="/hello",le="0.223696211",} 15680.0
http_server_requests_seconds_bucket{...,uri="/hello",le="0.246065832",} 15680.0
http_server_requests_seconds_bucket{...,uri="/hello",le="0.268435456",} 15680.0
http_server_requests_seconds_bucket{...,uri="/hello",le="0.357913941",} 15680.0
http_server_requests_seconds_bucket{...,uri="/hello",le="0.4",} 15687.0
http_server_requests_seconds_bucket{...,uri="/hello",le="0.447392426",} 16475.0
Monitor user experience by Apdex
32
Apdex = (Satisfied requests + Tolerating requests / 2)
/ Total number of requests
Satisfied: The response time is less than or equal to T.

Tolerating: The response time is greater than T and less than or equal to 4T.

Frustrated: The response time is greater than 4T.
https://docs.newrelic.com/docs/apm/new-relic-apm/apdex/apdex-measuring-user-satisfaction
For example, T = 1.2 [sec]
33
Level Multiplier Time (T Example = 1.2)
Satisfied T or less <= 1.2 seconds
Tolerating >T, <= 4T Between 1.2 and 4.8
seconds
Frustrated > 4T Greater than 4.8
seconds
https://docs.newrelic.com/docs/apm/new-relic-apm/apdex/apdex-measuring-user-satisfaction
34
• During a 2minute period a server handles 200 requests
• T = 1.2 [sec]
• 170 of the requests were handled within 1.2 sec
[Satisfied]
• 20 of the requests were handled between 1.2 sec and
4.8 sec [Tolerating]
• The remaining 10 took longer than 4.8 sec. [Frustrated]
• Appdex = (170 + (20 / 2)) / 200 = 0.9
For example, T = 1.2 [sec]
Query Appdex (T=100ms) in Prometheus
35
( sum(rate(http_server_requests_seconds_bucket{le="0.1",
status="200"}[5m])) by (app, uri) +
sum(rate(http_server_requests_seconds_bucket{le="0.4",
status="200"}[5m])) by (app, uri) )
https://prometheus.io/docs/practices/histograms/#apdex-score
Monitor Appdex in Grafana
36
Client-side Percentile
37
management.metrics.distribution.percentiles.http.server.r
equests=0.5, 0.9, 0.95, 0.99, 0.999
http_server_requests_seconds{...,uri="/hello",quantile="0.5",} 0.050855935
http_server_requests_seconds{...,uri="/hello",quantile="0.9",} 0.051380223
http_server_requests_seconds{...,uri="/hello",quantile="0.95",} 0.40265318
http_server_requests_seconds{...,uri="/hello",quantile="0.99",} 0.40265318
http_server_requests_seconds{...,uri="/hello",quantile="0.999",} 0.40265318
Percentiles for the specific uri in Prometheus
38
max(http_server_requests_seconds{uri="/hello",
status="200", exception="None"}) by (quantile)
Micrometer API
Meter (Timer, Counter, Gauge, ...)
40
@Component
public class FooService {
final Counter counter;
public FooService(MeterRegistry registry) {
this.counter = Counter.builder("received.messages")
.register(registry);
}
public void handleMessage() {
this.counter.increment();
}
}
Timer, Counter, Gauge, DistributionSummary, LongTaskTimer, FunctionCounte
r, FunctionTimer, and TimeGauge
Meter (Timer, Counter, Gauge, ...)
41
@Component
public class FooService {
final Timer timer;
public FooService(MeterRegistry registry) {
this.timer = Timer.builder("foo").register(registry);
}
public String foo() {
return this.timer.record(() -> {
// ...
});
}
}
Timer, Counter, Gauge, DistributionSummary, LongTaskTimer, FunctionCounte
r, FunctionTimer, and TimeGauge
@Timed
42
@Component
public class FooService {
@Timed("foo")
public String foo() {
// ...
}
}
@Bean
public TimedAspect timedAspect(MeterRegistry registry) {
return new TimedAspect(meterRegistry);
} // Not auto-configured in Spring Boot 2.0
https://github.com/micrometer-metrics/micrometer/issues/361
MeterFilter
43
@Bean
public MeterFilter meterFilter() {
return MeterFilter.deny(id -> {
String uri = id.getTag("uri");
return id != null && uri.startsWith("/actuator");
}
);
}
Exclude metrics against Actuator endpoints
Add MeterBinders
44
@Bean
public HystrixMetricsBinder hystrixMetricsBinder() {
return new HystrixMetricsBinder();
}
@Bean
public HibernateMetrics hibernateMetrics() {
return new HibernateMetrics(...);
}
Check io.micrometer.core.instrument.binder package
Some binders are auto-configured https://docs.spring.io/spring-boot/docs/2.0.x/reference/html/production-ready-
metrics.html#production-ready-metrics-meter
Enjoy Actuator & Micrometer!
45
Thank you for your attention!
• https://docs.spring.io/spring-boot/docs/2.0.x/reference/html/
production-ready.html
• https://micrometer.io/docs
• https://docs.spring.io/spring-boot/docs/2.0.x/reference/html/
production-ready-metrics.html
• https://blog.ik.am/entries/448
• https://github.com/making/demo-micrometer

More Related Content

What's hot

Zero-Copy Event-Driven Servers with Netty
Zero-Copy Event-Driven Servers with NettyZero-Copy Event-Driven Servers with Netty
Zero-Copy Event-Driven Servers with Netty
Daniel Bimschas
 

What's hot (20)

Micrometerでメトリクスを収集してAmazon CloudWatchで可視化
Micrometerでメトリクスを収集してAmazon CloudWatchで可視化Micrometerでメトリクスを収集してAmazon CloudWatchで可視化
Micrometerでメトリクスを収集してAmazon CloudWatchで可視化
 
なぜOpenID Connectが必要となったのか、その歴史的背景
なぜOpenID Connectが必要となったのか、その歴史的背景なぜOpenID Connectが必要となったのか、その歴史的背景
なぜOpenID Connectが必要となったのか、その歴史的背景
 
OAuth 2.0
OAuth 2.0OAuth 2.0
OAuth 2.0
 
Terraform Modules and Continuous Deployment
Terraform Modules and Continuous DeploymentTerraform Modules and Continuous Deployment
Terraform Modules and Continuous Deployment
 
Producer Performance Tuning for Apache Kafka
Producer Performance Tuning for Apache KafkaProducer Performance Tuning for Apache Kafka
Producer Performance Tuning for Apache Kafka
 
Discover Quarkus and GraalVM
Discover Quarkus and GraalVMDiscover Quarkus and GraalVM
Discover Quarkus and GraalVM
 
JVMに裏から手を出す!JVMTIに触れてみよう(オープンソースカンファレンス2020 Online/Hiroshima 講演資料)
JVMに裏から手を出す!JVMTIに触れてみよう(オープンソースカンファレンス2020 Online/Hiroshima 講演資料)JVMに裏から手を出す!JVMTIに触れてみよう(オープンソースカンファレンス2020 Online/Hiroshima 講演資料)
JVMに裏から手を出す!JVMTIに触れてみよう(オープンソースカンファレンス2020 Online/Hiroshima 講演資料)
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Terraform
TerraformTerraform
Terraform
 
Zero-Copy Event-Driven Servers with Netty
Zero-Copy Event-Driven Servers with NettyZero-Copy Event-Driven Servers with Netty
Zero-Copy Event-Driven Servers with Netty
 
OpenID Connect 入門 〜コンシューマーにおけるID連携のトレンド〜
OpenID Connect 入門 〜コンシューマーにおけるID連携のトレンド〜OpenID Connect 入門 〜コンシューマーにおけるID連携のトレンド〜
OpenID Connect 入門 〜コンシューマーにおけるID連携のトレンド〜
 
.NET 7 家族新成員: Microsoft Orleans v7
.NET 7 家族新成員:Microsoft Orleans v7.NET 7 家族新成員:Microsoft Orleans v7
.NET 7 家族新成員: Microsoft Orleans v7
 
Getting started with Ansible
Getting started with AnsibleGetting started with Ansible
Getting started with Ansible
 
Testing Spring Boot Applications
Testing Spring Boot ApplicationsTesting Spring Boot Applications
Testing Spring Boot Applications
 
Scalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsScalability, Availability & Stability Patterns
Scalability, Availability & Stability Patterns
 
怖くないSpring Bootのオートコンフィグレーション
怖くないSpring Bootのオートコンフィグレーション怖くないSpring Bootのオートコンフィグレーション
怖くないSpring Bootのオートコンフィグレーション
 
Mit 2014 introduction to open id connect and o-auth 2
Mit 2014   introduction to open id connect and o-auth 2Mit 2014   introduction to open id connect and o-auth 2
Mit 2014 introduction to open id connect and o-auth 2
 
Docker Container Security
Docker Container SecurityDocker Container Security
Docker Container Security
 
Cluster-as-code. The Many Ways towards Kubernetes
Cluster-as-code. The Many Ways towards KubernetesCluster-as-code. The Many Ways towards Kubernetes
Cluster-as-code. The Many Ways towards Kubernetes
 

Similar to Spring Boot Actuator 2.0 & Micrometer

Similar to Spring Boot Actuator 2.0 & Micrometer (20)

StackStrom: If-This-Than-That for Devops Automation
StackStrom: If-This-Than-That for Devops AutomationStackStrom: If-This-Than-That for Devops Automation
StackStrom: If-This-Than-That for Devops Automation
 
Event-driven automation, DevOps way ~IoT時代の自動化、そのリアリティとは?~
Event-driven automation, DevOps way ~IoT時代の自動化、そのリアリティとは?~Event-driven automation, DevOps way ~IoT時代の自動化、そのリアリティとは?~
Event-driven automation, DevOps way ~IoT時代の自動化、そのリアリティとは?~
 
jRecruiter - The AJUG Job Posting Service
jRecruiter - The AJUG Job Posting ServicejRecruiter - The AJUG Job Posting Service
jRecruiter - The AJUG Job Posting Service
 
Native support of Prometheus monitoring in Apache Spark 3
Native support of Prometheus monitoring in Apache Spark 3Native support of Prometheus monitoring in Apache Spark 3
Native support of Prometheus monitoring in Apache Spark 3
 
eBay Pulsar: Real-time analytics platform
eBay Pulsar: Real-time analytics platformeBay Pulsar: Real-time analytics platform
eBay Pulsar: Real-time analytics platform
 
OSMC 2021 | inspectIT Ocelot: Dynamic OpenTelemetry Instrumentation at Runtime
OSMC 2021 | inspectIT Ocelot: Dynamic OpenTelemetry Instrumentation at RuntimeOSMC 2021 | inspectIT Ocelot: Dynamic OpenTelemetry Instrumentation at Runtime
OSMC 2021 | inspectIT Ocelot: Dynamic OpenTelemetry Instrumentation at Runtime
 
Appium Automation with Kotlin
Appium Automation with KotlinAppium Automation with Kotlin
Appium Automation with Kotlin
 
Operator SDK for K8s using Go
Operator SDK for K8s using GoOperator SDK for K8s using Go
Operator SDK for K8s using Go
 
Getting Started with Apache Spark on Kubernetes
Getting Started with Apache Spark on KubernetesGetting Started with Apache Spark on Kubernetes
Getting Started with Apache Spark on Kubernetes
 
Context and Dependency Injection
Context and Dependency InjectionContext and Dependency Injection
Context and Dependency Injection
 
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
 
Feedback on building Production-Ready Microsoft Teams Apps
Feedback on building Production-Ready Microsoft Teams AppsFeedback on building Production-Ready Microsoft Teams Apps
Feedback on building Production-Ready Microsoft Teams Apps
 
Spring batch for large enterprises operations
Spring batch for large enterprises operations Spring batch for large enterprises operations
Spring batch for large enterprises operations
 
Naive application development
Naive application developmentNaive application development
Naive application development
 
Autoscaling in kubernetes v1
Autoscaling in kubernetes v1Autoscaling in kubernetes v1
Autoscaling in kubernetes v1
 
Why you should be using structured logs
Why you should be using structured logsWhy you should be using structured logs
Why you should be using structured logs
 
Monitoring with Prometheus
Monitoring with PrometheusMonitoring with Prometheus
Monitoring with Prometheus
 
Spring Performance Gains
Spring Performance GainsSpring Performance Gains
Spring Performance Gains
 
TYPO3 6.2. What's new
TYPO3 6.2. What's newTYPO3 6.2. What's new
TYPO3 6.2. What's new
 
Native Support of Prometheus Monitoring in Apache Spark 3.0
Native Support of Prometheus Monitoring in Apache Spark 3.0Native Support of Prometheus Monitoring in Apache Spark 3.0
Native Support of Prometheus Monitoring in Apache Spark 3.0
 

More from Toshiaki Maki

マイクロサービスに必要な技術要素はすべてSpring Cloudにある #DO07
マイクロサービスに必要な技術要素はすべてSpring Cloudにある #DO07マイクロサービスに必要な技術要素はすべてSpring Cloudにある #DO07
マイクロサービスに必要な技術要素はすべてSpring Cloudにある #DO07
Toshiaki Maki
 
実例で学ぶ、明日から使えるSpring Boot Tips #jsug
実例で学ぶ、明日から使えるSpring Boot Tips #jsug実例で学ぶ、明日から使えるSpring Boot Tips #jsug
実例で学ぶ、明日から使えるSpring Boot Tips #jsug
Toshiaki Maki
 

More from Toshiaki Maki (20)

From Spring Boot 2.2 to Spring Boot 2.3 #jsug
From Spring Boot 2.2 to Spring Boot 2.3 #jsugFrom Spring Boot 2.2 to Spring Boot 2.3 #jsug
From Spring Boot 2.2 to Spring Boot 2.3 #jsug
 
Concourse x Spinnaker #concourse_tokyo
Concourse x Spinnaker #concourse_tokyoConcourse x Spinnaker #concourse_tokyo
Concourse x Spinnaker #concourse_tokyo
 
Serverless with Spring Cloud Function, Knative and riff #SpringOneTour #s1t
Serverless with Spring Cloud Function, Knative and riff #SpringOneTour #s1tServerless with Spring Cloud Function, Knative and riff #SpringOneTour #s1t
Serverless with Spring Cloud Function, Knative and riff #SpringOneTour #s1t
 
決済システムの内製化への旅 - SpringとPCFで作るクラウドネイティブなシステム開発 #jsug #sf_h1
決済システムの内製化への旅 - SpringとPCFで作るクラウドネイティブなシステム開発 #jsug #sf_h1決済システムの内製化への旅 - SpringとPCFで作るクラウドネイティブなシステム開発 #jsug #sf_h1
決済システムの内製化への旅 - SpringとPCFで作るクラウドネイティブなシステム開発 #jsug #sf_h1
 
Open Service Broker APIとKubernetes Service Catalog #k8sjp
Open Service Broker APIとKubernetes Service Catalog #k8sjpOpen Service Broker APIとKubernetes Service Catalog #k8sjp
Open Service Broker APIとKubernetes Service Catalog #k8sjp
 
Spring Cloud Function & Project riff #jsug
Spring Cloud Function & Project riff #jsugSpring Cloud Function & Project riff #jsug
Spring Cloud Function & Project riff #jsug
 
Introduction to Spring WebFlux #jsug #sf_a1
Introduction to Spring WebFlux #jsug #sf_a1Introduction to Spring WebFlux #jsug #sf_a1
Introduction to Spring WebFlux #jsug #sf_a1
 
BOSH / CF Deployment in modern ways #cf_tokyo
BOSH / CF Deployment in modern ways #cf_tokyoBOSH / CF Deployment in modern ways #cf_tokyo
BOSH / CF Deployment in modern ways #cf_tokyo
 
Why PCF is the best platform for Spring Boot
Why PCF is the best platform for Spring BootWhy PCF is the best platform for Spring Boot
Why PCF is the best platform for Spring Boot
 
Zipkin Components #zipkin_jp
Zipkin Components #zipkin_jpZipkin Components #zipkin_jp
Zipkin Components #zipkin_jp
 
マイクロサービスに必要な技術要素はすべてSpring Cloudにある #DO07
マイクロサービスに必要な技術要素はすべてSpring Cloudにある #DO07マイクロサービスに必要な技術要素はすべてSpring Cloudにある #DO07
マイクロサービスに必要な技術要素はすべてSpring Cloudにある #DO07
 
Spring Framework 5.0による Reactive Web Application #JavaDayTokyo
Spring Framework 5.0による Reactive Web Application #JavaDayTokyoSpring Framework 5.0による Reactive Web Application #JavaDayTokyo
Spring Framework 5.0による Reactive Web Application #JavaDayTokyo
 
実例で学ぶ、明日から使えるSpring Boot Tips #jsug
実例で学ぶ、明日から使えるSpring Boot Tips #jsug実例で学ぶ、明日から使えるSpring Boot Tips #jsug
実例で学ぶ、明日から使えるSpring Boot Tips #jsug
 
Spring ❤️ Kotlin #jjug
Spring ❤️ Kotlin #jjugSpring ❤️ Kotlin #jjug
Spring ❤️ Kotlin #jjug
 
Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3
Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3
Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3
 
Managing your Docker image continuously with Concourse CI
Managing your Docker image continuously with Concourse CIManaging your Docker image continuously with Concourse CI
Managing your Docker image continuously with Concourse CI
 
Data Microservices with Spring Cloud Stream, Task, and Data Flow #jsug #spri...
Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #spri...Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #spri...
Data Microservices with Spring Cloud Stream, Task, and Data Flow #jsug #spri...
 
Short Lived Tasks in Cloud Foundry #cfdtokyo
Short Lived Tasks in Cloud Foundry #cfdtokyoShort Lived Tasks in Cloud Foundry #cfdtokyo
Short Lived Tasks in Cloud Foundry #cfdtokyo
 
今すぐ始めるCloud Foundry #hackt #hackt_k
今すぐ始めるCloud Foundry #hackt #hackt_k今すぐ始めるCloud Foundry #hackt #hackt_k
今すぐ始めるCloud Foundry #hackt #hackt_k
 
Team Support in Concourse CI 2.0 #concourse_tokyo
Team Support in Concourse CI 2.0 #concourse_tokyoTeam Support in Concourse CI 2.0 #concourse_tokyo
Team Support in Concourse CI 2.0 #concourse_tokyo
 

Recently uploaded

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

Spring Boot Actuator 2.0 & Micrometer

  • 1. 1 Spring Boot Actuator 2.0 & Micrometer 2018-03-27 Toshiaki Maki (@making / tmaki@pivotal.io)
  • 2. Who am I ? 2 Toshiaki Maki (@making) https://blog.ik.am Sr. Solutions Architect @Pivotal Japan Spring / Cloud Foundry / Concourse / Kubernetes " Spring Boot 2": https://note.ik.am (not free!)
  • 3. What' new in Spring Boot 2 X • Infrastructure Update (Spring 5, Tomcat 8.5, Jetty 9.4, Hibernete 5.3, HikariCP as a default CP) • Starters for reactive projects • Reactive web test support • new OAuth 2 support • explicit Spring Security configurations • Actuator refactoring / Micrometer support • Kotlin support
  • 4. Agenda 3 • Spring Boot Actuator 2 • Micrometer • Micrometer • Histograms and percentiles • Micrometer API
  • 6. Spring Boot Actuator 5 Additional features to help you monitor and manage your application in production. <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
  • 7. Supported Endpoints 6 • auditevents • beans • conditions • configprops • env • flyway • health • httptrace https://demo-micrometer.cfapps.io/actuator https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html • info • loggers • liquibase • metrics • mappings • scheduledtasks • sessions • shutdown • threaddump • heapdump • jolokia • logfile • prometheus /actuator/* •renamed •added
  • 8. Technology Support 7 Spring Boot Actuator 1.x Spring Boot Actuator 2.x •Spring MVC •Spring MVC •Spring WebFlux •Jersey
  • 9. How to enable endpoints 8 Default exposed endpoints are /info and /health. management.endpoints.web.exposure.include=* management.endpoints.web.exposure.include=info,health,env All endpoints are not secured by default.
  • 10. Secure endpoints (Spring MVC) 9 http.authorizeRequests() .mvcMatchers("/actuator/health", "/actuator/info") .permitAll() .mvcMatchers("/actuator/**")
 .hasRole("ACTUATOR") .anyRequest() .permitAll() .and() .httpBasic() .and()...
  • 11. Secure endpoints (Spring MVC) 9 http.authorizeRequests() .mvcMatchers("/actuator/health", "/actuator/info") .permitAll() .mvcMatchers("/actuator/**")
 .hasRole("ACTUATOR") .anyRequest() .permitAll() .and() .httpBasic() .and()... spring.security.user.name=hoge spring.security.user.password=foo spring.security.user.roles=ACTUATOR
  • 12. Secure endpoints (Spring MVC) 10 http.authorizeRequests() .requestMatchers(EndpointRequest.to("health", "info")) .permitAll() .requestMatchers(EndpointRequest.toAnyEndpoint())
 .hasRole("ACTUATOR") .anyRequest() .permitAll() .and() .httpBasic() .and()...
  • 13. Secure endpoints (Spring WebFlux) 11 http.authorizeExchange() .matchers(EndpointRequest.to("health", "info")) .permitAll() .matchers(EndpointRequest.toAnyEndpoint())
 .hasRole("ACTUATOR") .anyExchange() .permitAll() .and() .httpBasic() .and()...
  • 15. Cloud Foundry Support 13 https://docs.spring.io/spring-boot/docs/2.0.x/reference/html/production-ready-cloudfoundry.html
  • 17. Micrometer 15 Move to Micrometer Think SLF4J, but for Metrics Instrument without vendor lock-in: • Prometheus • Netflix Atlas • Datadog • InfluxDB • ... Multi-dementional metrics https://micrometer.io/
  • 18. Supported monitoring systems 16 Server polls Client pushes Prometheus Atlas, Datadog, Datadog StatsD, Influx, SignalFx, Telegraf StatsD, Wavefront, New Relic Dimensional Graphite, Ganglia, JMX, Etsy StatsD, PCF Metrics 1.4 Hierarchical push poll
  • 20. /actuator/prometheus 18 system_cpu_count 4.0 system_load_average_1m 1.64 jvm_memory_max_bytes{area="heap",id="PS Eden Space",} 1.05906176E8 jvm_memory_max_bytes{area="heap",id="PS Survivor Space",} 2.1495808E7 jvm_memory_max_bytes{area="heap",id="PS Old Gen",} 3.00941312E8 http_server_requests_seconds_count{exception="None",method="GET" ,status="200",uri="/hello",} 4469.0 http_server_requests_seconds_sum{exception="None",method="GET",s tatus="200",uri="/hello",} 297.942920787 http_server_requests_seconds_max{exception="None",method="GET",s tatus="200",uri="/hello",} 0.401581731 https://docs.spring.io/spring-boot/docs/2.0.x/reference/html/production-ready-metrics.html#production-ready- metrics-meter
  • 23. On Cloud Foundry 21 @Bean @Profile("cloud") public MeterRegistryCustomizer meterRegistryCustomizer( @Value("${vcap.application.name:}") String name, @Value("${vcap.application.instance_id:}") String id) { return registry -> registry.config() .commonTags("cf_app_name", name, "cf_app_instance_id", id); }
  • 24. On Cloud Foundry 22 system_cpu_count{cf_app_instance_id="31388366-...",cf_app_name=" demo-micrometer",} } 4.0 system_load_average_1m{cf_app_instance_id="31388366-...",cf_app_ name="demo-micrometer",} 1.64 jvm_memory_max_bytes{cf_app_instance_id="31388366-...",cf_app_na me="demo-micrometer",area="heap",id="PS Eden Space",} 1.05906176E8 jvm_memory_max_bytes{cf_app_instance_id="31388366-...",cf_app_na me="demo-micrometer",area="heap",id="PS Survivor Space",} 2.1495808E7 jvm_memory_max_bytes{cf_app_instance_id="31388366-...",cf_app_na me="demo-micrometer",area="heap",id="PS Old Gen",} 3.00941312E8
  • 27. PCF Metrics 25 Bind Metrics Forwarder Service https://github.com/cloudfoundry/java-buildpack-metric-writer Use Metric Writer 2.4.0+ which comes with JBP 4.10+
  • 30. Histogram in Prometheus 28 http_server_requests_seconds_bucket{...,uri="/hello",le="0.061516456",} 15646.0 http_server_requests_seconds_bucket{...,uri="/hello",le="0.067108864",} 15657.0 http_server_requests_seconds_bucket{...,uri="/hello",le="0.089478485",} 15679.0 http_server_requests_seconds_bucket{...,uri="/hello",le="0.111848106",} 15679.0 http_server_requests_seconds_bucket{...,uri="/hello",le="0.134217727",} 15680.0 http_server_requests_seconds_bucket{...,uri="/hello",le="0.156587348",} 15680.0 http_server_requests_seconds_bucket{...,uri="/hello",le="0.178956969",} 15680.0 http_server_requests_seconds_bucket{...,uri="/hello",le="0.20132659",} 15680.0 http_server_requests_seconds_bucket{...,uri="/hello",le="0.223696211",} 15680.0 http_server_requests_seconds_bucket{...,uri="/hello",le="0.246065832",} 15680.0 http_server_requests_seconds_bucket{...,uri="/hello",le="0.268435456",} 15680.0 http_server_requests_seconds_bucket{...,uri="/hello",le="0.357913941",} 15680.0 http_server_requests_seconds_bucket{...,uri="/hello",le="0.447392426",} 16475.0 The number of requests that took less than 0.447392426 sec.
  • 31. Query percentiles in Prometheus 29 histogram_quantile(0.9, sum(rate(http_server_requests_seconds_bucket{status="200" }[5m])) by (app, uri, le)) https://prometheus.io/docs/prometheus/latest/querying/functions/#histogram_quantile()
  • 32. SLA (Service Level Agreement) 30 management.metrics.distribution.sla.http.server.requests= 100ms, 200ms, 400ms
  • 33. SLA in Prometheus 31 http_server_requests_seconds_bucket{...,uri="/hello",le="0.061516456",} 15646.0 http_server_requests_seconds_bucket{...,uri="/hello",le="0.067108864",} 15657.0 http_server_requests_seconds_bucket{...,uri="/hello",le="0.089478485",} 15679.0 http_server_requests_seconds_bucket{...,uri="/hello",le="0.1",} 15679.0 http_server_requests_seconds_bucket{...,uri="/hello",le="0.111848106",} 15679.0 http_server_requests_seconds_bucket{...,uri="/hello",le="0.134217727",} 15680.0 http_server_requests_seconds_bucket{...,uri="/hello",le="0.156587348",} 15680.0 http_server_requests_seconds_bucket{...,uri="/hello",le="0.178956969",} 15680.0 http_server_requests_seconds_bucket{...,uri="/hello",le="0.2",} 15680.0 http_server_requests_seconds_bucket{...,uri="/hello",le="0.20132659",} 15680.0 http_server_requests_seconds_bucket{...,uri="/hello",le="0.223696211",} 15680.0 http_server_requests_seconds_bucket{...,uri="/hello",le="0.246065832",} 15680.0 http_server_requests_seconds_bucket{...,uri="/hello",le="0.268435456",} 15680.0 http_server_requests_seconds_bucket{...,uri="/hello",le="0.357913941",} 15680.0 http_server_requests_seconds_bucket{...,uri="/hello",le="0.4",} 15687.0 http_server_requests_seconds_bucket{...,uri="/hello",le="0.447392426",} 16475.0
  • 34. Monitor user experience by Apdex 32 Apdex = (Satisfied requests + Tolerating requests / 2) / Total number of requests Satisfied: The response time is less than or equal to T. Tolerating: The response time is greater than T and less than or equal to 4T. Frustrated: The response time is greater than 4T. https://docs.newrelic.com/docs/apm/new-relic-apm/apdex/apdex-measuring-user-satisfaction
  • 35. For example, T = 1.2 [sec] 33 Level Multiplier Time (T Example = 1.2) Satisfied T or less <= 1.2 seconds Tolerating >T, <= 4T Between 1.2 and 4.8 seconds Frustrated > 4T Greater than 4.8 seconds https://docs.newrelic.com/docs/apm/new-relic-apm/apdex/apdex-measuring-user-satisfaction
  • 36. 34 • During a 2minute period a server handles 200 requests • T = 1.2 [sec] • 170 of the requests were handled within 1.2 sec [Satisfied] • 20 of the requests were handled between 1.2 sec and 4.8 sec [Tolerating] • The remaining 10 took longer than 4.8 sec. [Frustrated] • Appdex = (170 + (20 / 2)) / 200 = 0.9 For example, T = 1.2 [sec]
  • 37. Query Appdex (T=100ms) in Prometheus 35 ( sum(rate(http_server_requests_seconds_bucket{le="0.1", status="200"}[5m])) by (app, uri) + sum(rate(http_server_requests_seconds_bucket{le="0.4", status="200"}[5m])) by (app, uri) ) https://prometheus.io/docs/practices/histograms/#apdex-score
  • 38. Monitor Appdex in Grafana 36
  • 39. Client-side Percentile 37 management.metrics.distribution.percentiles.http.server.r equests=0.5, 0.9, 0.95, 0.99, 0.999 http_server_requests_seconds{...,uri="/hello",quantile="0.5",} 0.050855935 http_server_requests_seconds{...,uri="/hello",quantile="0.9",} 0.051380223 http_server_requests_seconds{...,uri="/hello",quantile="0.95",} 0.40265318 http_server_requests_seconds{...,uri="/hello",quantile="0.99",} 0.40265318 http_server_requests_seconds{...,uri="/hello",quantile="0.999",} 0.40265318
  • 40. Percentiles for the specific uri in Prometheus 38 max(http_server_requests_seconds{uri="/hello", status="200", exception="None"}) by (quantile)
  • 42. Meter (Timer, Counter, Gauge, ...) 40 @Component public class FooService { final Counter counter; public FooService(MeterRegistry registry) { this.counter = Counter.builder("received.messages") .register(registry); } public void handleMessage() { this.counter.increment(); } } Timer, Counter, Gauge, DistributionSummary, LongTaskTimer, FunctionCounte r, FunctionTimer, and TimeGauge
  • 43. Meter (Timer, Counter, Gauge, ...) 41 @Component public class FooService { final Timer timer; public FooService(MeterRegistry registry) { this.timer = Timer.builder("foo").register(registry); } public String foo() { return this.timer.record(() -> { // ... }); } } Timer, Counter, Gauge, DistributionSummary, LongTaskTimer, FunctionCounte r, FunctionTimer, and TimeGauge
  • 44. @Timed 42 @Component public class FooService { @Timed("foo") public String foo() { // ... } } @Bean public TimedAspect timedAspect(MeterRegistry registry) { return new TimedAspect(meterRegistry); } // Not auto-configured in Spring Boot 2.0 https://github.com/micrometer-metrics/micrometer/issues/361
  • 45. MeterFilter 43 @Bean public MeterFilter meterFilter() { return MeterFilter.deny(id -> { String uri = id.getTag("uri"); return id != null && uri.startsWith("/actuator"); } ); } Exclude metrics against Actuator endpoints
  • 46. Add MeterBinders 44 @Bean public HystrixMetricsBinder hystrixMetricsBinder() { return new HystrixMetricsBinder(); } @Bean public HibernateMetrics hibernateMetrics() { return new HibernateMetrics(...); } Check io.micrometer.core.instrument.binder package Some binders are auto-configured https://docs.spring.io/spring-boot/docs/2.0.x/reference/html/production-ready- metrics.html#production-ready-metrics-meter
  • 47. Enjoy Actuator & Micrometer! 45 Thank you for your attention! • https://docs.spring.io/spring-boot/docs/2.0.x/reference/html/ production-ready.html • https://micrometer.io/docs • https://docs.spring.io/spring-boot/docs/2.0.x/reference/html/ production-ready-metrics.html • https://blog.ik.am/entries/448 • https://github.com/making/demo-micrometer