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>
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.
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()
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
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