Spring Boot Actuator

Spring boot actuator provides in-built HTTP endpoints available for different monitoring and management purposes.

It provides several features like health check-up, auditing JVM metrics, log information, caching statics, etc.

We need to add the spring-boot-starter-actuator Spring Boot Starter in our dependency.

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

For the HTTP, by default exposure is enabled only for info and health endpoints.

Hit http://localhost:8080/actuator, it displays the exposed end points

http://localhost:8080/actuator

{
“_links”: {
“self”: {
“href”: “http://localhost:8080/actuator”,
“templated”: false
},
“health”: {
“href”: “http://localhost:8080/actuator/health”,
“templated”: false
},
“info”: {
“href”: “http://localhost:8080/actuator/info”,
“templated”: false
}
}
}
We can enable other endpoints by adding the following in application.properties
management.endpoints.web.exposure.include= health,info,beans,heapdump,env,metrics
http://localhost:8080/actuator – returns the below response now.
{
“_links”: {
“self”: {
“href”: “http://localhost:8080/actuator”,
“templated”: false
},
“beans”: {
“href”: “http://localhost:8080/actuator/beans”,
“templated”: false
},
“health”: {
“href”: “http://localhost:8080/actuator/health”,
“templated”: false
},
“env”: {
“href”: “http://localhost:8080/actuator/env”,
“templated”: false
},
“env-toMatch”: {
“href”: “http://localhost:8080/actuator/env/{toMatch}”,
“templated”: true
},
“info”: {
“href”: “http://localhost:8080/actuator/info”,
“templated”: false
},
“heapdump”: {
“href”: “http://localhost:8080/actuator/heapdump”,
“templated”: false
},
“metrics”: {
“href”: “http://localhost:8080/actuator/metrics”,
“templated”: false
},
“metrics-requiredMetricName”: {
“href”: “http://localhost:8080/actuator/metrics/{requiredMetricName}”,
“templated”: true
}
}
}
We can enable all endpoints by adding the below in application.properties
management.endpoints.web.exposure.include= *
http://localhost:8080/actuator – returns the below response now.
{
“_links”: {
“self”: {
“href”: “http://localhost:8080/actuator”,
“templated”: false
},
“auditevents”: {
“href”: “http://localhost:8080/actuator/auditevents”,
“templated”: false
},
“beans”: {
“href”: “http://localhost:8080/actuator/beans”,
“templated”: false
},
“health”: {
“href”: “http://localhost:8080/actuator/health”,
“templated”: false
},
“conditions”: {
“href”: “http://localhost:8080/actuator/conditions”,
“templated”: false
},
“configprops”: {
“href”: “http://localhost:8080/actuator/configprops”,
“templated”: false
},
“env”: {
“href”: “http://localhost:8080/actuator/env”,
“templated”: false
},
“env-toMatch”: {
“href”: “http://localhost:8080/actuator/env/{toMatch}”,
“templated”: true
},
“info”: {
“href”: “http://localhost:8080/actuator/info”,
“templated”: false
},
“loggers”: {
“href”: “http://localhost:8080/actuator/loggers”,
“templated”: false
},
“loggers-name”: {
“href”: “http://localhost:8080/actuator/loggers/{name}”,
“templated”: true
},
“heapdump”: {
“href”: “http://localhost:8080/actuator/heapdump”,
“templated”: false
},
“threaddump”: {
“href”: “http://localhost:8080/actuator/threaddump”,
“templated”: false
},
“metrics-requiredMetricName”: {
“href”: “http://localhost:8080/actuator/metrics/{requiredMetricName}”,
“templated”: true
},
“metrics”: {
“href”: “http://localhost:8080/actuator/metrics”,
“templated”: false
},
“scheduledtasks”: {
“href”: “http://localhost:8080/actuator/scheduledtasks”,
“templated”: false
},
“httptrace”: {
“href”: “http://localhost:8080/actuator/httptrace”,
“templated”: false
},
“mappings”: {
“href”: “http://localhost:8080/actuator/mappings”,
“templated”: false
}
}
}
All endpoints
Spring Boot Actuator
Let’s look into few of important endpoints.
health

It shows application health information. This endpoint only display a simple status of the application like UP or DOWN.

http://localhost:8080/actuator/health
Response:
{
“status”: “UP”
}
info

Add application info like name, description etc in application.properties.

The info endpoints displays application info.

application.properties

info.name= Spring RESTful WebService
info.more.detail= RESTful WebService using Spring and Spring Boot
management.endpoints.web.exposure.include= *

http://localhost:8080/actuator/info
Response: 
{
“name”: “Spring RESTful WebService”,
“more”: {
“detail”: “RESTful WebService using Spring and Spring Boot”
}
}
env

env endpoint gives us all environment informations.

http://localhost:8080/actuator/env
Response: 
{
“activeProfiles”: [],
“propertySources”: [{
“name”: “server.ports”,
“properties”: {
“local.server.port”: {
“value”: 8080
}
}
}, {
“name”: “servletContextInitParams”,
“properties”: {}
}, {
“name”: “systemProperties”,
“properties”: {…}
}, {
“name”: “systemEnvironment”,
“properties”: {…}
}, {
“name”: “applicationConfig: [classpath:/application.properties]”,
“properties”: {
“info.name”: {
“value”: “Spring RESTful WebService”,
“origin”: “class path resource [application.properties]:1:12”
},
“info.more.detail”: {
“value”: “RESTful WebService using Spring and Spring Boot”,
“origin”: “class path resource [application.properties]:2:19”
},
“management.endpoints.web.exposure.include”: {
“value”: “*”,
“origin”: “class path resource [application.properties]:3:44”
}
}
}, {
“name”: “class path resource [database.properties]”,
“properties”: {
“url”: {
“value”: “jdbc:mysql://localhost:3306/testschema”
},
“dbpassword”: {
“value”: “******”
},
“driver”: {
“value”: “com.mysql.jdbc.Driver”
},
“dbuser”: {
“value”: “root”
}
}
}]
}
beans

It displays a complete list of all the Spring beans in the application.

http://localhost:8080/actuator/beans
Response: 
{
“contexts”: {
“application”: {
“beans”: {
“endpointCachingOperationInvokerAdvisor”: {
“aliases”: [],
“scope”: “singleton”,
“type”: “org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvokerAdvisor”,
“resource”: “class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/EndpointAutoConfiguration.class]”,
“dependencies”: [“environment”]
},
“defaultServletHandlerMapping”: {
“aliases”: [],
“scope”: “singleton”,
“type”: “org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport$EmptyHandlerMapping”,
“resource”: “class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]”,
“dependencies”: []
},
“org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter$FaviconConfiguration”: {
“aliases”: [],
“scope”: “singleton”,
“type”: “org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter$FaviconConfiguration$$EnhancerBySpringCGLIB$$3ee5ec9c”,
“resource”: null,
“dependencies”: [“spring.resources-org.springframework.boot.autoconfigure.web.ResourceProperties”]
},
    …..
    …..
    …..
“platformTransactionManagerCustomizers”: {
“aliases”: [],
“scope”: “singleton”,
“type”: “org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers”,
“resource”: “class path resource [org/springframework/boot/autoconfigure/transaction/TransactionAutoConfiguration.class]”,
“dependencies”: []
}
},
“parentId”: null
}
}
}
metrics
metrics endpoint gives us all the metrics which we can track for our application.
http://localhost:8080/actuator/metrics
Response: 
{
“names”: [“jvm.memory.max”, “http.server.requests”, “process.files.max”, “jvm.gc.memory.promoted”, 
“tomcat.cache.hit”, “system.load.average.1m”, “tomcat.cache.access”, “jvm.memory.used”, “jvm.gc.max.data.size”, 
“jvm.gc.pause”, “jvm.memory.committed”, “system.cpu.count”, “logback.events”, “tomcat.global.sent”, “jvm.buffer.memory.used”, 
“tomcat.sessions.created”, “jvm.threads.daemon”, “system.cpu.usage”, “jvm.gc.memory.allocated”, “tomcat.global.request.max”, 
“tomcat.global.request”, “tomcat.sessions.expired”, “jvm.threads.live”, “jvm.threads.peak”, “tomcat.global.received”, 
“process.uptime”, “tomcat.sessions.rejected”, “process.cpu.usage”, “tomcat.threads.config.max”, “jvm.classes.loaded”, 
“jvm.classes.unloaded”, “tomcat.global.error”, “tomcat.sessions.active.current”, “tomcat.sessions.alive.max”, 
“jvm.gc.live.data.size”, “tomcat.servlet.request.max”, “tomcat.threads.current”, “tomcat.servlet.request”, “process.files.open”,
“jvm.buffer.count”, “jvm.buffer.total.capacity”, “tomcat.sessions.active.max”, “tomcat.threads.busy”, “process.start.time”, “tomcat.servlet.error”]
}
Individual metrics

We can track individual metric by passing specific metric to the URL after /metrics endpoint.

http://localhost:8080/actuator/metrics/jvm.memory.used
Response: 
{
“name”: “jvm.memory.used”,
“description”: “The amount of used memory”,
“baseUnit”: “bytes”,
“measurements”: [{
“statistic”: “VALUE”,
“value”: 2.54611984E8
}],
“availableTags”: [{
“tag”: “area”,
“values”: [“heap”, “nonheap”]
}, {
“tag”: “id”,
“values”: [“Compressed Class Space”, “PS Survivor Space”, “PS Old Gen”, “Metaspace”, “PS Eden Space”, “Code Cache”]
}]
}
heapdump

http://localhost:8080/actuator/heapdump

heapdump endpoint gives Heap dump from the application JVM. This endpoint returns binary data in HPROF format.

Leave a Reply

Your email address will not be published. Required fields are marked *