Spring Boot – Actuator setup

Spring Boot actuator provides useful metrics regarding your application like health, configurations, error pages, version information, etc. Setting up and using an Actuator in Spring Boot could not be easier than adding the correct dependency in the pom.xml file and using the appropriate url to access the metric information.

We are going to add to our existing spring boot app. Lets start with updating the pom.xml to include the Actuator dependency.

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

 

Here we have added the Actuator in the pom xml and this would enable the GAV to be imported and included in our application right away. This also adds access to the following end points for metric information about the current application.

– /beans

– /info

– /metrics

– /dump, etc

 

Now lets add the following properties to the application.properties file to provide some basic information about the app.

endpoints.info.id=info
endpoints.info.sensitive=false
endpoints.info.enabled=true
info.app.name=AtechRef Spring Actuator Sample
info.app.description=Working sample of a Spring Boot Actuator
info.app.version=1.0.0-SNAPSHOT

Restart the Spring Boot app and when you try and access the following url’s you would get similar results as shown below. Note that some of the responses are really long and have been truncated for clarity.

http://localhost:8080/beans

[{"context":"application","parent":null,"beans":[{"bean":"app","scope":"singleton","type":"com.atechref.spring.App$$EnhancerBySpringCGLIB$$686827e1","resource":"null","dependencies":[]},{"bean":"org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration","scope":"singleton","type":"org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration$$EnhancerBySpringCGLIB$$bc1ffe31","resource":"null","dependencies":[]},{"bean":"org.springframework.boot.autoconfigure.condition.BeanTypeRegistry","scope":"singleton","type":"org.springframework.boot.autoconfigure.condition.BeanTypeRegistry$OptimizedBeanTypeRegistry","resource":"null","dependencies":[]},{"bean":"org.springframework.boot.autoconfigure.websocket.WebSocketAutoConfiguration","scope":"singleton","type":"org.springframework.boot.autoconfigure.websocket.WebSocketAutoConfiguration$$EnhancerBySpringCGLIB$$923bc64f","resource":"null","dependencies":[]},{"bean":"org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration$EmbeddedTomcat","scope":"singleton","type":"org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration$EmbeddedTomcat$$EnhancerBySpringCGLIB$$1afec93","resource":"null","dependencies":[]},{"bean":"tomcatEmbeddedServletContainerFactory","scope":"singleton","type":"org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory","resource":"class path resource [org/springframework/boot/autoconfigure/web/EmbeddedServletContainerAutoConfiguration$EmbeddedTomcat.class]","dependencies":[]},{"bean":"org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration","scope":"singleton","type":"org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration$$EnhancerBySpringCGLIB$$cf3ea537","resource":"null","dependencies":[]},{"bean":"embeddedServletContainerCustomizerBeanPostProcessor","scope":"singleton","type":"org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizerBeanPostProcessor","resource":"null","dependencies":[]},.....

 

– http://localhost:8080/info

{"app":{"version":"1.0.0-SNAPSHOT","description":"Working sample of a Spring Boot Actuator","name":"AtechRef Spring Actuator Sample"}}

 

– http://localhost:8080/metrics

{"mem":262209,"mem.free":97520,"processors":4,"instance.uptime":214747,"uptime":223122,"systemload.average":-1.0,"heap.committed":211968,"heap.init":131072,"heap.used":114447,"heap":1840640,"nonheap.committed":51072,"nonheap.init":2496,"nonheap.used":50241,"nonheap":0,"threads.peak":22,"threads.daemon":20,"threads.totalStarted":26,"threads":22,"classes":6155,"classes.loaded":6155,"classes.unloaded":0,"gc.ps_scavenge.count":7,"gc.ps_scavenge.time":198,"gc.ps_marksweep.count":1,"gc.ps_marksweep.time":137,"httpsessions.max":-1,"httpsessions.active":0,"gauge.response.metrics":5.0,"gauge.response.info":133.0,"gauge.response.star-star.favicon.ico":4.0,"counter.status.200.info":1,"counter.status.200.star-star.favicon.ico":6,"counter.status.200.metrics":8}

 

– http://localhost:8080/dump

[{"threadName":"http-nio-8080-exec-10","threadId":32,"blockedTime":-1,"blockedCount":0,"waitedTime":-1,"waitedCount":1,"lockName":"java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject@36d7f9e","lockOwnerId":-1,"lockOwnerName":null,"inNative":false,"suspended":false,"threadState":"WAITING","stackTrace":[{"methodName":"park","fileName":"Unsafe.java","lineNumber":-2,"className":"sun.misc.Unsafe","nativeMethod":true},{"methodName":"park","fileName":"LockSupport.java","lineNumber":175,"className":"java.util.concurrent.locks.LockSupport","nativeMethod":false},{"methodName":"await","fileName":"AbstractQueuedSynchronizer.java","lineNumber":2039,"className":"java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject","nativeMethod":false},{"methodName":"take","fileName":"LinkedBlockingQueue.java","lineNumber":442,"className":"java.util.concurrent.LinkedBlockingQueue","nativeMethod":false},{"methodName":"take","fileName":"TaskQueue.java","lineNumber":103,"className":"org.apache.tomcat.util.threads.TaskQueue","nativeMethod":false},{"methodName":"invokeHandlerMethod","fileName":"RequestMappingHandlerAdapter.java","lineNumber":817,"className":"org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter","nativeMethod":false},.....

Actuator for Spring Boor is now enabled and functional for your application.

Leave a Reply

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