Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Better monitoring with Spring boot Actuator
Search
Dimitri
July 27, 2020
Programming
0
260
Better monitoring with Spring boot Actuator
An overview of the features Spring boot actuator has to offer.
Dimitri
July 27, 2020
Tweet
Share
More Decks by Dimitri
See All by Dimitri
Intro to Astro
g00glen00b
0
81
Moduliths
g00glen00b
0
83
Tech talk: Micronaut
g00glen00b
0
170
From WordPress to Gatsby
g00glen00b
3
300
GraphQL
g00glen00b
1
220
Reactive programming with Spring boot 2
g00glen00b
1
290
Introduction to Meteor
g00glen00b
0
300
JavaScript essentials
g00glen00b
3
370
Fronteers - JavaScript at your enterprise (Dutch)
g00glen00b
0
150
Other Decks in Programming
See All in Programming
WEBアプリケーションにおけるAWS Lambdaを用いた大規模な非同期処理の実践
delhi09
PRO
7
4.1k
Pythonによるイベントソーシングへの挑戦と現状に対する考察 / Challenging Event Sourcing with Python and Reflections on the Current State
nrslib
3
1.2k
モジュラモノリス、その前に / Modular monolith, before that
euglena1215
6
690
Iteratorでページネーションを実現する
sonatard
3
720
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
9
1.3k
Go製CLIツールGatling Commanderによる負荷試験実施の自動化
okmtz
3
700
"noncopyable types" の使いどころについて考えてみた
andpad
0
150
UnJSで簡単に始めるCLIツール開発 / cli-tool-development-with-unjs
aoseyuu
2
290
MLOps in Mercari Group’s Trust and Safety ML Team
cjhj
1
120
Повторное использование кода в ML: почему ML-пайплайны могут помочь?
lamodatech
0
160
Remix × Cloudflare Pages × Sentry 奮闘記 / remix-pages-sentry
nkzn
1
420
個人開発で使ってるやつを紹介する回
yohfee
1
700
Featured
See All Featured
For a Future-Friendly Web
brad_frost
174
9.3k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
27
1.9k
Teambox: Starting and Learning
jrom
132
8.7k
Faster Mobile Websites
deanohume
304
30k
Docker and Python
trallard
40
3k
Documentation Writing (for coders)
carmenintech
65
4.4k
[RailsConf 2023] Rails as a piece of cake
palkan
49
4.7k
StorybookのUI Testing Handbookを読んだ
zakiyama
26
5.1k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
41
9.2k
Optimising Largest Contentful Paint
csswizardry
31
2.8k
Designing on Purpose - Digital PM Summit 2013
jponch
114
6.9k
Building Better People: How to give real-time feedback that sticks.
wjessup
362
19k
Transcript
Better monitoring with Spring boot Actuator
What is Spring boot Actuator? • Spring boot library •
Adds production-ready features • Provides useful endpoints • Both over HTTP and JMX
Which endpoints are there? • Auditevents • Beans • Caches
• Conditions • Configprops • Env • Flyway • Health • Heapdump • Httptrace • Info • Integrationgraph • Jolokia • Logfile • Loggers • Liquibase • Metrics • Mappings • Prometheus • Scheduledtasks • Sessions • Shutdown • Threaddump
How do I get started?
Add a dependency... <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
… and configure what you need management: endpoints: web: exposure:
include: env, info, health, metrics
And… what now?
Visit /actuator { "_links": { "self": { "href": "http://192.168.0.220:8080/actuator", "templated":
false }, "health": { "href": "http://192.168.0.220:8080/actuator/health", "templated": false } }
Exploring the conditions endpoint
What does it do? • Which autoconfigurations are in use
• Why are they (not) applied? • What can I do to make it work?
Visit /actuator/conditions { "positiveMatches": {/* ... */}, "negativeMatches": { "RabbitHealthContributorAutoConfiguration":
{ "notMatched": [ { "condition": "OnClassCondition", "message": "@ConditionalOnClass did not find required class 'org.springframework.amqp.rabbit.core.RabbitTemplate'" } ]
Exploring the env endpoint
What does it do? • Which application properties are loaded?
• Where do these properties come from?
Visit /actuator/env { "activeProfiles": [ "dev" ], "propertySources": [ {
"name": "applicationConfig: [classpath:/application-dev.yml]", "properties": { "server.port": { "value": 8080, "origin": "class path resource [application-dev.yml]:2:9"
Exploring the health endpoint
What does it do? • Is the database available? •
Is there enough disk space? • Is Eureka available? • Is Solr available? • Useful for monitoring software • ...
Visit /actuator/health { "status": "UP" }
Showing detailed health info management: endpoint: health: show-details: always
Showing detailed health info { "status": "UP", "components": { "db":
{ "status": "UP", "details": { "database": "DB2 UDB for AS/400", "validationQuery": "SELECT 1 FROM SYSIBM.SYSDUMMY1", "result": 1 } }
Creating a custom health indicator @Component @RequiredArgsConstructor public class GitHubAPIHealthIndicator
implements HealthIndicator { private final RestTemplate restTemplate; @Override public Health health() { // TODO: implement } }
Creating a custom health indicator try { var result =
restTemplate.getForEntity("https://api.github.com/", ObjectNode.class); if (result.getStatusCode().is2xxSuccessful() && result.getBody() != null) { return Health.up().build(); } else { return Health.down().withDetail("status", result.getStatusCode()).build(); } } catch (RestClientException ex) { return Health.down().withException(ex).build(); }
Creating a custom health indicator { "status": "UP", "components": {
"gitHubAPI": { "status": "UP" } } }
Useful for monitoring
Useful for Eureka
Exploring the heapdump endpoint
What does it do? • Returns *.HPROF file • Can
be imported in JVisualVM, … • Find memory leaks and other peformance issues
Open the *.HPROF file
Exploring the info endpoint
What does it do? • Returns additional information • By
default empty • Useful in combination with Maven resource filtering
Configuring info info: contributors: Dimitri Mestdagh project-version: @project-version@ build-timestamp: @maven.build.timestamp@
Visit /actuator/info { "contributors": "Dimitri Mestdagh", "project-version": "0.0.1-SNAPSHOT", "build-timestamp": "2020-06-27
11:52:30" }
Exploring the loggers endpoint
What does it do? • What logging levels are in
use? • Change runtime logging levels • Useful for debugging
Visit /actuator/loggers { "loggers": { "ROOT": { "configuredLevel": "INFO", "effectiveLevel":
"INFO" }, "be.g00glen00b": { "configuredLevel": null, "effectiveLevel": "INFO" } } }
Changing the runtime logger levels curl \ --header "Content-Type: application/json"
\ --request POST \ --data '{"configuredLevel": "DEBUG"}' \ http://localhost:8080/actuator/loggers/be.g00glen00b
Exploring the metrics endpoint
What does it do? • Application metrics • Uses micrometer
• Counters • Gauges • Distribution summaries • Percentiles • Timers
Visit /actuator/metrics { "names": [ "cache.evictions", "http.server.requests", "jvm.threads.states", "hystrix.execution", "spring.batch.chunk.write",
"spring.batch.item.process", "hystrix.latency.total", "jvm.memory.used" ] }
Visit /actuator/metrics/{metric} { "name": "jvm.memory.used", "description": "The amount of used
memory", "baseUnit": "bytes", "measurements": [{ "statistic": "VALUE", "value": 196616376 }], "availableTags": [{ "tag": "area", "values": ["heap", "nonheap"] }]
Visit /actuator/metrics/{metric}?tag=area:heap { "name": "jvm.memory.used", "description": "The amount of used
memory", "baseUnit": "bytes", "measurements": [{ "statistic": "VALUE", "value": 196616376 }], "availableTags": [] }
Creating custom counter metrics @Bean public Counter invoicesCounter(MeterRegistry registry) {
return Counter .builder("invoices.created") .description("Amount of invoices created") .register(registry); }
Creating custom counter metrics @PostMapping public CreatedInvoiceDTO create(@RequestBody InvoiceParametersDTO parameters)
{ counter.increment(); // Add this return facade.create(parameters); }
Creating custom gauge metrics @Bean public Gauge countOrdersGauge(MeterRegistry registry, OrderRepository
repository) { return Gauge .builder("order.count", repository::count) .description("Amount of registered orders”) .register(registry); }
Cool stuff… but why?
Cool stuff… but why? • Production-readiness • Better monitoring •
Better logging • Better debugging = More happy people
Resources • https://docs.spring.io/spring-boot/docs/current/reference/html/p roduction-ready-features.html • https://dimitr.im/mastering-spring-boot-actuator Shameless self-promotion
Thank you for listening!