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. Trouble in containerized applications / micro services!!
!3
💥 Out of memory error!
💥 Performance issue!
🤔
GC log
Heap Dump
Thread
Dump
Method
Profiling
4. 💥 Out of memory error!
💥 Performance issue!
What you will get from this session
!4
5. 💥 Out of memory error!
💥 Performance issue!
What you will get from this session
!4
6. 💥 Out of memory error!
💥 Performance issue!
What you will get from this session
!4
7. 💥 Out of memory error!
💥 Performance issue!
What you will get from this session
!4
😎
8. Agenda
!5
• Spring Boot Actuator 2
• Micrometer
• Micrometer
• Histograms and percentiles
• Micrometer API
• Monitoring Spring Boot apps
on Cloud Foundry and
Kubernetes
10. Spring Boot Actuator
!7
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>
13. How to enable endpoints
!10
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.
38. PCF Metrics
!33
Bind Metrics Forwarder Service
https://github.com/cloudfoundry/java-buildpack-metric-writer Use Metric Writer 2.4.0+ which comes with JBP 4.10+
39. Also work with Spring Boot 1
!34
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-spring-legacy</artifactId>
<version>${micrometer.version}</version>
</dependency>
42. Histogram in Prometheus
!37
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.
43. Query percentiles in Prometheus
!38
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()
48. Meter (Timer, Counter, Gauge, ...)
!43
Timer, Counter, Gauge, DistributionSummary, LongTaskTimer, FunctionCounte
r, FunctionTimer, and TimeGauge
@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();
}
}
49. Meter (Timer, Counter, Gauge, ...)
!44
@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
50. @Timed
!45
@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
51. Tag
!46
@Component
public class TweetCounter {
final MeterRegistry registry;
public FooService(MeterRegistry registry) {
this.counter = registry;
}
public void countTweet(String name, String hashTag) {
this.registry.counter("tweet",
"screen_name", name,
"hash_tag", hashTag)
.increment();
}
}
52. MeterFilter
!47
@Bean
public MeterFilter meterFilter() {
return MeterFilter.deny(id -> {
String uri = id.getTag("uri");
return id != null && uri.startsWith("/actuator");
}
);
}
Exclude metrics against Actuator endpoints
53. Add MeterBinders
!48
@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
63. Related Links
!58
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
• https://github.com/making/demo-prom-grafana-on-cf (CF env)
• https://github.com/categolj/blog-prometheus/tree/master/local (Local &k8s env)
64. Related Talks
!59
• More Spring Boot 2? => 13:30-14:15 @Room E+F
Pivotal Reactive
Spring 5 & Spring Boot 2
• More Observability? => 14:30-15:15 @Room I
How to Properly Blame Things for Causing Latency:
An Introduction to Distributed Tracing and Zipkin